use of io.servicetalk.client.api.partition.PartitionAttributes in project servicetalk by apple.
the class DefaultPartitionAttributesBuilderTest method notEqualsDifferentKeys.
@Test
void notEqualsDifferentKeys() {
DefaultPartitionAttributesBuilder builder = new DefaultPartitionAttributesBuilder(3);
builder.add(SHARD_KEY, DEFAULT_SHARD);
builder.add(DC_KEY, DEFAULT_DC);
builder.add(MAIN_KEY, true);
PartitionAttributes partitionAttributes = builder.build();
builder = new DefaultPartitionAttributesBuilder(3);
builder.add(DC_KEY, DEFAULT_DC);
builder.add(MAIN_KEY, true);
builder.add(OTHER_KEY, 2);
PartitionAttributes partitionAttributes2 = builder.build();
assertNotEquals(partitionAttributes, partitionAttributes2);
assertSize(partitionAttributes, 3);
assertEquals(DEFAULT_SHARD, partitionAttributes.get(SHARD_KEY));
assertEquals(DEFAULT_DC, partitionAttributes.get(DC_KEY));
assertEquals(true, partitionAttributes.get(MAIN_KEY));
assertNull(partitionAttributes.get(OTHER_KEY));
assertSize(partitionAttributes2, 3);
assertEquals(true, partitionAttributes2.get(MAIN_KEY));
assertEquals(DEFAULT_DC, partitionAttributes2.get(DC_KEY));
assertEquals((Integer) 2, partitionAttributes2.get(OTHER_KEY));
assertNull(partitionAttributes2.get(SHARD_KEY));
}
use of io.servicetalk.client.api.partition.PartitionAttributes in project servicetalk by apple.
the class DefaultPartitionAttributesBuilderTest method notEqualsSameKeysDifferentValues.
@Test
void notEqualsSameKeysDifferentValues() {
DefaultPartitionAttributesBuilder builder = new DefaultPartitionAttributesBuilder(2);
builder.add(SHARD_KEY, DEFAULT_SHARD);
builder.add(DC_KEY, DEFAULT_DC);
builder.add(MAIN_KEY, true);
PartitionAttributes partitionAttributes = builder.build();
builder = new DefaultPartitionAttributesBuilder(3);
builder.add(DC_KEY, DEFAULT_DC);
builder.add(MAIN_KEY, false);
builder.add(SHARD_KEY, DEFAULT_SHARD);
PartitionAttributes partitionAttributes2 = builder.build();
assertNotEquals(partitionAttributes, partitionAttributes2);
assertSize(partitionAttributes, 3);
assertEquals(DEFAULT_SHARD, partitionAttributes.get(SHARD_KEY));
assertEquals(DEFAULT_DC, partitionAttributes.get(DC_KEY));
assertEquals(true, partitionAttributes.get(MAIN_KEY));
assertSize(partitionAttributes2, 3);
assertEquals(false, partitionAttributes2.get(MAIN_KEY));
assertEquals(DEFAULT_DC, partitionAttributes2.get(DC_KEY));
assertEquals(DEFAULT_SHARD, partitionAttributes2.get(SHARD_KEY));
}
use of io.servicetalk.client.api.partition.PartitionAttributes in project servicetalk by apple.
the class DefaultPartitionAttributesBuilderTest method notEqualsMissingKey.
@Test
void notEqualsMissingKey() {
DefaultPartitionAttributesBuilder builder = new DefaultPartitionAttributesBuilder(3);
builder.add(SHARD_KEY, DEFAULT_SHARD);
builder.add(DC_KEY, DEFAULT_DC);
builder.add(MAIN_KEY, true);
PartitionAttributes partitionAttributes = builder.build();
builder = new DefaultPartitionAttributesBuilder(2);
builder.add(DC_KEY, DEFAULT_DC);
builder.add(MAIN_KEY, true);
PartitionAttributes partitionAttributes2 = builder.build();
assertNotEquals(partitionAttributes, partitionAttributes2);
assertSize(partitionAttributes, 3);
assertEquals(DEFAULT_SHARD, partitionAttributes.get(SHARD_KEY));
assertEquals(DEFAULT_DC, partitionAttributes.get(DC_KEY));
assertEquals(true, partitionAttributes.get(MAIN_KEY));
assertSize(partitionAttributes2, 2);
assertEquals(true, partitionAttributes2.get(MAIN_KEY));
assertEquals(DEFAULT_DC, partitionAttributes2.get(DC_KEY));
}
use of io.servicetalk.client.api.partition.PartitionAttributes in project servicetalk by apple.
the class PowerSetPartitionMap method remove.
@Override
public List<T> remove(PartitionAttributes partition) {
Set<PartitionAttributes> removedWildCardAttributes = absoluteToWildCardIndexMap.remove(partition);
if (removedWildCardAttributes == null) {
return emptyList();
}
// Make a copy of the current wildCardToValueMap because we will copy/swap
Map<PartitionAttributes, ValueHolder<T>> newWildCardToAttributes = new HashMap<>(wildCardToValueMap);
List<T> effectedPartitions = new ArrayList<>(removedWildCardAttributes.size());
for (PartitionAttributes wildCardAttribute : removedWildCardAttributes) {
ValueHolder<T> valueHolder = newWildCardToAttributes.get(wildCardAttribute);
assert valueHolder != null;
if (--valueHolder.refCount == 0) {
newWildCardToAttributes.remove(wildCardAttribute);
}
effectedPartitions.add(valueHolder.value);
}
wildCardToValueMap = newWildCardToAttributes;
return effectedPartitions;
}
use of io.servicetalk.client.api.partition.PartitionAttributes in project servicetalk by apple.
the class PowerSetPartitionMapTest method testAddDuplicationPartitions.
@Test
void testAddDuplicationPartitions() {
PowerSetPartitionMap<ListenableAsyncCloseable> map = new PowerSetPartitionMap<>(address -> VALUE);
assertTrue(map.isEmpty(), "New map is not empty.");
PartitionAttributes partition = new DefaultPartitionAttributesBuilder(1).add(IS_MAIN, true).add(SHARD_ID, 1).build();
List<ListenableAsyncCloseable> added1 = map.add(partition);
List<ListenableAsyncCloseable> added2 = map.add(partition);
assertEquals(added1, added2, "Added partitions are not equal.");
assertEquals(1, map.size(), "Same partition added twice.");
List<ListenableAsyncCloseable> removed = map.remove(partition);
assertEquals(removed.size(), added1.size(), "Unexpected size of removed partitions.");
}
Aggregations