Search in sources :

Example 11 with PartitionAttributes

use of io.servicetalk.client.api.partition.PartitionAttributes in project servicetalk by apple.

the class DefaultPartitionAttributesBuilderTest method equalsAndHashCode.

@Test
void equalsAndHashCode() {
    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(SHARD_KEY, DEFAULT_SHARD);
    PartitionAttributes partitionAttributes2 = builder.build();
    assertEquals(partitionAttributes, partitionAttributes2);
    assertEquals(partitionAttributes.hashCode(), partitionAttributes2.hashCode());
    assertSize(partitionAttributes, 3);
    assertEquals(DEFAULT_SHARD, partitionAttributes2.get(SHARD_KEY));
    assertEquals(DEFAULT_DC, partitionAttributes2.get(DC_KEY));
    assertEquals(true, partitionAttributes2.get(MAIN_KEY));
    assertSize(partitionAttributes2, 3);
    assertEquals(true, partitionAttributes2.get(MAIN_KEY));
    assertEquals(DEFAULT_DC, partitionAttributes2.get(DC_KEY));
    assertEquals(DEFAULT_SHARD, partitionAttributes2.get(SHARD_KEY));
}
Also used : PartitionAttributes(io.servicetalk.client.api.partition.PartitionAttributes) Test(org.junit.jupiter.api.Test)

Example 12 with PartitionAttributes

use of io.servicetalk.client.api.partition.PartitionAttributes in project servicetalk by apple.

the class DefaultPartitionAttributesBuilderTest method addFourItemsSortedCorrectlyB.

@Test
void addFourItemsSortedCorrectlyB() {
    PartitionAttributesBuilder builder = new DefaultPartitionAttributesBuilder(4);
    builder.add(SHARD_KEY, DEFAULT_SHARD);
    builder.add(MAIN_KEY, false);
    builder.add(DC_KEY, DEFAULT_DC);
    builder.add(OTHER_KEY, 2);
    PartitionAttributes partitionAttributes = builder.build();
    assertSize(partitionAttributes, 4);
    assertEquals(DEFAULT_SHARD, partitionAttributes.get(SHARD_KEY));
    assertEquals(DEFAULT_DC, partitionAttributes.get(DC_KEY));
    assertEquals((Integer) 2, partitionAttributes.get(OTHER_KEY));
    assertEquals(false, partitionAttributes.get(MAIN_KEY));
}
Also used : PartitionAttributes(io.servicetalk.client.api.partition.PartitionAttributes) PartitionAttributesBuilder(io.servicetalk.client.api.partition.PartitionAttributesBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

PartitionAttributes (io.servicetalk.client.api.partition.PartitionAttributes)12 Test (org.junit.jupiter.api.Test)10 ListenableAsyncCloseable (io.servicetalk.concurrent.api.ListenableAsyncCloseable)4 PartitionAttributesBuilder (io.servicetalk.client.api.partition.PartitionAttributesBuilder)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 PartitionMap (io.servicetalk.client.api.partition.PartitionMap)1 AsyncCloseable (io.servicetalk.concurrent.api.AsyncCloseable)1 AsyncCloseables.toAsyncCloseable (io.servicetalk.concurrent.api.AsyncCloseables.toAsyncCloseable)1 Completable (io.servicetalk.concurrent.api.Completable)1 Integer.bitCount (java.lang.Integer.bitCount)1 Integer.numberOfTrailingZeros (java.lang.Integer.numberOfTrailingZeros)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Set (java.util.Set)1 Function (java.util.function.Function)1