Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BRBussy
Copy link
Contributor

@BRBussy BRBussy commented Oct 23, 2025

Summary

This PR adds group context switching functionality to Java and Python SDKs, bringing them to full feature parity with the Go SDK. It also includes a cleanup of deprecated methods in the Go Amount type.

Key Improvements:

  • ✅ Java SDK: Added withGroup() method for context switching
  • ✅ Python SDK: Added with_group() method with centralized architecture
  • ✅ Go SDK: Removed deprecated IsEqual() method for API consistency
  • ✅ All SDKs now at 100% feature parity
  • ✅ Zero breaking changes for existing code

Changes by Language

🟦 Java SDK

Added withGroup() Method (1cd6504)

Enables convenient group context switching while preserving all other client configuration.

Implementation:

  • Added createOptionsWithGroup() protected helper to BaseGRPCClient
  • Updated InterfaceGenerator to add withGroup() method signature to all service interfaces
  • Updated ClientGenerator to generate withGroup() implementation in all service clients
  • Returns new client instance with different group context, all other config preserved

Testing:

  • ✅ Added comprehensive WithGroupTest with 3 test cases:
    • Creates new instance with different group
    • Clients are independent (closing one doesn't affect other)
    • Preserves all configuration except group (URL, port, API key, timeout, TLS)
  • ✅ All 54 tests pass with zero regressions

Files Changed:

java/src/main/java/co/meshtrade/api/grpc/BaseGRPCClient.java          (+31 lines)
java/src/test/java/co/meshtrade/api/grpc/WithGroupTest.java           (+108 lines)
tool/protoc-gen-meshjava/src/.../generator/ClientGenerator.java       (+54 lines)
tool/protoc-gen-meshjava/src/.../generator/InterfaceGenerator.java    (+49 lines)

Example Usage:

// Create initial client with default group
GroupService service = new GroupService();

// Switch to different group context
GroupServiceInterface altService = service.withGroup("groups/01ARZ3NDEKTSV4RRFFQ69G5FAV");

// Both clients can be used independently
service.someMethod(request);      // Uses original group
altService.someMethod(request);   // Uses alternative group

🐍 Python SDK

Added with_group() Method with Centralized Architecture (b8c7afb)

Implements convenient group context switching matching Go SDK's WithGroup() functionality, with significant architecture improvements.

Implementation:

  • Added with_group() method to BaseGRPCClient with comprehensive validation
  • Created shared ServiceOptions class in meshtrade.common.service_options (eliminates duplication)
  • Added property accessors to BaseGRPCClient for configuration access
  • Updated code generator to import shared ServiceOptions instead of generating per-service copies
  • Validation ensures group parameter is non-empty and follows groups/{id} format

Architecture Improvements:

  • DRY Compliance: with_group() logic defined once in base class, inherited by all services
  • Eliminated Duplication: Removed 9+ duplicate ServiceOptions files across service packages
  • Centralized Validation: Clear error messages in base class
  • Consistent Pattern: Matches Go SDK architecture

Testing:

  • ✅ Added comprehensive test suite (test_with_group.py) with 8 test cases:
    • Returns new instance (not same object)
    • Changes group context correctly
    • Preserves URL, port, API key, timeout, TLS settings
    • Allows independent usage of both clients
    • Validates empty group (raises ValueError)
    • Validates malformed group format (raises ValueError)
  • ✅ All 140 tests pass with zero regressions

Files Changed:

python/src/meshtrade/common/grpc_client.py                       (+93 lines)
python/src/meshtrade/common/service_options.py                   (+46 lines NEW)
python/src/meshtrade/*/v1/__init__.py                            (-18 lines across 9 files)
python/tests/unit/common/test_with_group.py                      (+169 lines NEW)
tool/protoc-gen-meshpy/main.py                                   (+8/-8 lines)
tool/protoc-gen-meshpy/templates/service_meshpy.py.j2            (+1/-1 lines)

Example Usage:

# Create initial client with default group from credentials
service = ApiUserService()

# Switch to different group context
alt_service = service.with_group("groups/01ARZ3NDEKTSV4RRFFQ69G5FAV")

# Both clients can be used independently
resp1 = service.get_api_user(request)      # Uses original group
resp2 = alt_service.get_api_user(request)  # Uses alternative group

🔵 Go SDK

Removed Deprecated IsEqual() Method (5456aa8)

Removes the deprecated Amount.IsEqual() method in favor of the standardized IsEqualTo() method for API consistency with Token.IsEqualTo().

Changes:

  • Removed Amount.IsEqual() method from amount.go
  • Removed TestAmount_IsEqual test function
  • Removed IsEqual nil safety test case from TestAmount_NilSafetyIntegration

Rationale:

  • IsEqualTo() follows consistent naming with Token.IsEqualTo()
  • Eliminates API confusion with two similar methods
  • Reduces maintenance burden

Files Changed:

go/type/v1/amount.go        (-33 lines)
go/type/v1/amount_test.go   (-75 lines)

Migration:

// Before (deprecated)
if amount.IsEqual(other) { ... }

// After (use this)
if amount.IsEqualTo(other) { ... }

Testing Summary

All Tests Passing ✅

SDK Test Count Status
Java 54 tests ✅ All passing
Python 140 tests ✅ All passing
Go All tests ✅ All passing

Breaking Changes

⚠️ Go SDK Only: Removed deprecated Amount.IsEqual() method

  • Impact: Users calling IsEqual() will get compilation error
  • Migration: Replace IsEqual() with IsEqualTo()
  • Note: IsEqualTo() has been available since v1.0.0

Java & Python: ✅ No breaking changes - all additions are additive


Feature Parity Status

All three SDKs now have 100% feature parity for group context switching:

Feature Go SDK Java SDK Python SDK
Group context switching WithGroup() withGroup() with_group()
Validation ✅ Empty check ✅ Delegated to builder ✅ Empty + format check
Creates new instance ✅ Yes ✅ Yes ✅ Yes
Preserves config ✅ Yes ✅ Yes ✅ Yes
Independent clients ✅ Yes ✅ Yes ✅ Yes
Test coverage ✅ Comprehensive ✅ Comprehensive ✅ Comprehensive

Review Checklist

  • All tests passing (Java: 54, Python: 140, Go: all)
  • Code generators updated for future services
  • Comprehensive test coverage added
  • Documentation in commit messages
  • Zero regressions in existing functionality
  • Breaking change documented (Go Amount.IsEqual only)

Related Issues

Implements group context switching functionality across all SDKs for multi-tenant operations.


🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

BRBussy and others added 4 commits October 23, 2025 15:31
- Add createOptionsWithGroup helper to BaseGRPCClient
- Generate withGroup method in all service clients via InterfaceGenerator and ClientGenerator
- Add comprehensive integration tests in WithGroupTest
- Enables convenient group context switching while preserving all other configuration
- All 54 tests pass with zero regressions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Removes the deprecated Amount.IsEqual method and all related tests in favor of the standardized IsEqualTo method for API consistency with Token.IsEqualTo.

Changes:
- Remove Amount.IsEqual method from amount.go
- Remove TestAmount_IsEqual test function
- Remove IsEqual nil safety test case from TestAmount_NilSafetyIntegration

All tests pass and golangci-lint reports no issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implements convenient group context switching for Python SDK clients, matching
the Go SDK's WithGroup functionality. This enables users to easily create new
client instances with different group contexts while preserving all other
configuration.

Changes:
- Added with_group() method to BaseGRPCClient with validation for empty and
  malformed group parameters
- Created shared ServiceOptions class (meshtrade.common.service_options) to
  eliminate duplication across all service packages
- Added property accessors to BaseGRPCClient (url, port, api_key, timeout, tls)
  for configuration access
- Updated code generator to import shared ServiceOptions instead of generating
  per-service copies, removing 9+ duplicate files
- Updated code generator to remove ClientOptions from service package exports
- Added comprehensive test coverage with 8 test cases verifying all aspects of
  with_group behavior
- All 140 tests pass with zero regressions

Architecture improvements:
- DRY compliance: with_group logic defined once, inherited by all services
- Validation centralized in base class with clear error messages
- Consistent with Go SDK architecture pattern
- Eliminates code duplication across service packages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@BRBussy BRBussy merged commit 26b7e00 into master Oct 23, 2025
@BRBussy BRBussy deleted the update-sdk-clients branch October 23, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants