@Test public void testChoosePartitionWithoutKey() { Message<?> msg = mock(Message.class); when(msg.getKey()).thenReturn(null); SinglePartitionMessageRouterImpl router = new SinglePartitionMessageRouterImpl(1234, HashingScheme.JavaStringHash); assertEquals(1234, router.choosePartition(msg, new TopicMetadataImpl(2468))); }
@Override public int choosePartition(Message<?> msg, TopicMetadata metadata) { if (msg.hasKey()) { return signSafeMod(hash.makeHash(msg.getKey()), metadata.numPartitions()); } return partitionIndex; }
SinglePartitionMessageRouterImpl extends MessageRouterBase { @Override public int choosePartition(Message<?> msg, TopicMetadata metadata) { if (msg.hasKey()) { return signSafeMod(hash.makeHash(msg.getKey()), metadata.numPartitions()); } return partitionIndex; } }
SinglePartitionMessageRouterImpl extends MessageRouterBase { @Override public int choosePartition(Message<?> msg, TopicMetadata metadata) { if (msg.hasKey()) { return signSafeMod(hash.makeHash(msg.getKey()), metadata.numPartitions()); } return partitionIndex; } SinglePartitionMessageRouterImpl(int partitionIndex, HashingScheme hashingScheme); }
SinglePartitionMessageRouterImpl extends MessageRouterBase { @Override public int choosePartition(Message<?> msg, TopicMetadata metadata) { if (msg.hasKey()) { return signSafeMod(hash.makeHash(msg.getKey()), metadata.numPartitions()); } return partitionIndex; } SinglePartitionMessageRouterImpl(int partitionIndex, HashingScheme hashingScheme); @Override int choosePartition(Message<?> msg, TopicMetadata metadata); }
SinglePartitionMessageRouterImpl extends MessageRouterBase { @Override public int choosePartition(Message<?> msg, TopicMetadata metadata) { if (msg.hasKey()) { return signSafeMod(hash.makeHash(msg.getKey()), metadata.numPartitions()); } return partitionIndex; } SinglePartitionMessageRouterImpl(int partitionIndex, HashingScheme hashingScheme); @Override int choosePartition(Message<?> msg, TopicMetadata metadata);  }