use of io.servicetalk.client.api.partition.PartitionAttributesBuilder in project servicetalk by apple.
the class PartitionedHttpClientTest method testPartitionByTarget.
@Test
void testPartitionByTarget() throws Exception {
final Function<HttpRequestMetaData, PartitionAttributesBuilder> selector = req -> new DefaultPartitionAttributesBuilder(1).add(SRV_NAME, req.requestTarget().substring(1));
try (BlockingHttpClient clt = HttpClients.forPartitionedAddress(psd, "test-cluster", selector).initializer((pa, builder) -> builder.unresolvedAddressToHost(addr -> pa.get(SRV_NAME))).buildBlocking()) {
sdPublisher.onSubscribe(new TestSubscription());
sdPublisher.onNext(new TestPSDE(SRV_1, (InetSocketAddress) srv1.listenAddress()), new TestPSDE(SRV_2, (InetSocketAddress) srv2.listenAddress()));
final HttpResponse httpResponse1 = clt.request(clt.get("/" + SRV_2));
final HttpResponse httpResponse2 = clt.request(clt.get("/" + SRV_1));
MatcherAssert.assertThat(httpResponse1.headers().get(X_SERVER), hasToString(SRV_2));
MatcherAssert.assertThat(httpResponse2.headers().get(X_SERVER), hasToString(SRV_1));
}
}
use of io.servicetalk.client.api.partition.PartitionAttributesBuilder in project servicetalk by apple.
the class PowerSetPartitionMapTest method testWildCardResolveTwoElements.
@Test
void testWildCardResolveTwoElements() {
PowerSetPartitionMap<ListenableAsyncCloseable> map = oneTwoThreeMap();
PartitionAttributesBuilder builder = new DefaultPartitionAttributesBuilder(2);
builder.add(DC_ID, 1);
builder.add(SHARD_ID, 10);
assertEquals(VALUE, map.get(builder.build()));
builder = new DefaultPartitionAttributesBuilder(2);
builder.add(DC_ID, 1);
builder.add(SHARD_ID, 9);
assertEquals(VALUE, map.get(builder.build()));
builder = new DefaultPartitionAttributesBuilder(2);
builder.add(DC_ID, 1);
builder.add(APP_ID, "myapp");
assertEquals(VALUE, map.get(builder.build()));
builder = new DefaultPartitionAttributesBuilder(2);
builder.add(APP_ID, "myapp");
builder.add(IS_MAIN, true);
assertEquals(VALUE, map.get(builder.build()));
builder = new DefaultPartitionAttributesBuilder(2);
builder.add(APP_ID, "myapp");
builder.add(IS_MAIN, false);
assertEquals(VALUE, map.get(builder.build()));
builder = new DefaultPartitionAttributesBuilder(2);
builder.add(DC_ID, 1);
builder.add(IS_MAIN, false);
assertEquals(VALUE, map.get(builder.build()));
builder = new DefaultPartitionAttributesBuilder(2);
builder.add(DC_ID, 1);
builder.add(IS_MAIN, true);
assertEquals(VALUE, map.get(builder.build()));
builder = new DefaultPartitionAttributesBuilder(2);
builder.add(DC_ID, 2);
builder.add(IS_MAIN, true);
assertNull(map.get(builder.build()));
}
use of io.servicetalk.client.api.partition.PartitionAttributesBuilder in project servicetalk by apple.
the class PowerSetPartitionMapTest method testRemoveOfOverlappingAttributesPreservesValue.
@Test
void testRemoveOfOverlappingAttributesPreservesValue() {
PowerSetPartitionMap<ListenableAsyncCloseable> map = oneTwoThreeMap();
// Test remove
List<ListenableAsyncCloseable> result = map.remove(host3Attributes());
assertEquals(VALUE, map.get(host1Attributes()));
assertEquals(VALUE, map.get(host2Attributes()));
assertNull(map.get(host3Attributes()));
assertEquals(15, result.size());
// Test a wild card with a unique attribute to host3 removed no longer returns any results.
PartitionAttributesBuilder builder = new DefaultPartitionAttributesBuilder(1);
builder.add(SHARD_ID, 9);
PartitionAttributes partitionAttributes = builder.build();
assertNull(map.get(partitionAttributes));
// Test the same key, but different value still returns results.
builder = new DefaultPartitionAttributesBuilder(1);
builder.add(SHARD_ID, 10);
partitionAttributes = builder.build();
assertNotNull(map.get(partitionAttributes));
}
use of io.servicetalk.client.api.partition.PartitionAttributesBuilder in project servicetalk by apple.
the class PowerSetPartitionMapTest method host3Attributes.
private static PartitionAttributes host3Attributes() {
PartitionAttributesBuilder builder = new DefaultPartitionAttributesBuilder(4);
builder.add(DC_ID, 1);
builder.add(SHARD_ID, 9);
builder.add(APP_ID, "myapp");
builder.add(IS_MAIN, true);
return builder.build();
}
use of io.servicetalk.client.api.partition.PartitionAttributesBuilder in project servicetalk by apple.
the class PowerSetPartitionMapTest method host4Attributes.
private static PartitionAttributes host4Attributes() {
PartitionAttributesBuilder builder = new DefaultPartitionAttributesBuilder(4);
builder.add(DC_ID, 1);
builder.add(SHARD_ID, 8);
builder.add(APP_ID, "myapp");
builder.add(IS_MAIN, true);
return builder.build();
}
Aggregations