test(spanner): add a mock server test using key-aware routing#12755
test(spanner): add a mock server test using key-aware routing#12755
Conversation
Adds a mock server test that uses key-aware routing. This test is not testing much interesting, but serves as a base for future tests that can run against a mock server to test for example replica selection.
There was a problem hiding this comment.
Code Review
This pull request modifies MockSpannerServiceImpl to include CacheUpdate in PartialResultSet and removes a restriction on key sizes in isValidKeySet. It also introduces ReplicaSelectionMockServerTest to test end-to-end directed read routing. The review feedback identifies a mismatch in the mock server's statement registration that would cause test failures, and recommends removing an unused field and its redundant cleanup logic.
| com.google.cloud.spanner.Statement readStatement = | ||
| StatementResult.createReadStatement( | ||
| "Table", | ||
| com.google.cloud.spanner.KeySet.singleKey(com.google.cloud.spanner.Key.of()), | ||
| Arrays.asList("Column")); |
There was a problem hiding this comment.
The readStatement is registered with an empty key (Key.of()), but the actual read calls in the polling loop (line 281) use non-empty keys (e.g., "key-1"). In MockSpannerServiceImpl, the registered statement must match the request exactly (including the serialized key set). This mismatch will cause the mock server to return an error as it won't find a matching result. Consider using a consistent fixed key for both registration and the read calls.
| com.google.cloud.spanner.Statement readStatement = | |
| StatementResult.createReadStatement( | |
| "Table", | |
| com.google.cloud.spanner.KeySet.singleKey(com.google.cloud.spanner.Key.of()), | |
| Arrays.asList("Column")); | |
| String key = "key-1"; | |
| com.google.cloud.spanner.Statement readStatement = | |
| StatementResult.createReadStatement( | |
| "Table", | |
| com.google.cloud.spanner.KeySet.singleKey(com.google.cloud.spanner.Key.of(key)), | |
| Arrays.asList("Column")); |
|
|
||
| while (watch.elapsed(TimeUnit.SECONDS) < 10) { | ||
| attempt++; | ||
| String key = "key-" + attempt; |
|
|
||
| private List<ServerInstance> servers; | ||
| private final int numServers = 2; | ||
| private KeyAwareChannel keyAwareChannel; |
| if (keyAwareChannel != null) { | ||
| keyAwareChannel.shutdown(); | ||
| } |
Adds a mock server test that uses key-aware routing. This test is not testing much interesting, but serves as a base for future tests that can run against a mock server to test for example replica selection.