@Test public void shouldReturnLeadingPartitionsForNodeId() { // given final PartitionsLeaderMatrix partitionsLeaderMatrix = new PartitionsLeaderMatrix(6, 5, 3); // when final IntArrayList leadingPartitions = partitionsLeaderMatrix.getLeadingPartitions(0); // then assertThat(leadingPartitions).containsExactly(0, 5); }
@Test public void shouldReturnMembersForPartitionWithoutSelf() { // given final PartitionsLeaderMatrix partitionsLeaderMatrix = new PartitionsLeaderMatrix(6, 5, 3); // when final IntArrayList membersForPartition = partitionsLeaderMatrix.getMembersForPartition(0, 5); // then assertThat(membersForPartition).containsExactly(1, 2); }
@Test public void shouldReturnFollowingPartitionsForNodeId() { // given final PartitionsLeaderMatrix partitionsLeaderMatrix = new PartitionsLeaderMatrix(6, 5, 3); // when final IntArrayList followingPartitions = partitionsLeaderMatrix.getFollowingPartitions(1); // then assertThat(followingPartitions).containsExactly(0, 4, 5); }
@Test public void shouldReturnLeadingPartitionsForNodeId() { // given final PartitionsLeaderMatrix partitionsLeaderMatrix = new PartitionsLeaderMatrix(6, 5, 3); // when final IntArrayList leadingPartitions = partitionsLeaderMatrix.getLeadingPartitions(0); // then assertThat(leadingPartitions).containsExactly(0, 5); }
@Test public void shouldReturnMembersForPartition() { // given final PartitionsLeaderMatrix partitionsLeaderMatrix = new PartitionsLeaderMatrix(6, 5, 3); // when final IntArrayList membersForPartition = partitionsLeaderMatrix.getMembersForPartition(0, 1); // then assertThat(membersForPartition).containsExactly(1, 2, 3); }
@Test public void shouldCreatePartitionsMatrixWithMoreNodesThenPartitionsAndReplicationFactor() { // given final PartitionsLeaderMatrix partitionsLeaderMatrix = new PartitionsLeaderMatrix(1, 2, 2); // then final int[][] matrix = partitionsLeaderMatrix.matrix; assertThat(matrix).hasSize(1); assertThat(matrix[0]).hasSize(2); assertThat(matrix[0]).containsExactly(LEADER, FOLLOWER); }
@Test public void shouldCreateDefaultPartitionsMatrix() { // given final PartitionsLeaderMatrix partitionsLeaderMatrix = new PartitionsLeaderMatrix(1, 1, 1); // then final int[][] matrix = partitionsLeaderMatrix.matrix; assertThat(matrix).hasSize(1); assertThat(matrix[0]).hasSize(1); assertThat(matrix).containsExactly(new int[] {LEADER}); }
@Test public void shouldCreatePartitionsMatrixWithMoreNodesThenPartitions() { // given final PartitionsLeaderMatrix partitionsLeaderMatrix = new PartitionsLeaderMatrix(1, 2, 1); // then final int[][] matrix = partitionsLeaderMatrix.matrix; assertThat(matrix).hasSize(1); assertThat(matrix[0]).hasSize(2); assertThat(matrix[0]).containsExactly(LEADER, 0); }
@Test public void shouldCreatePartitionsMatrixWithMorePartitionsThenNodes() { // given final PartitionsLeaderMatrix partitionsLeaderMatrix = new PartitionsLeaderMatrix(2, 1, 1); // then final int[][] matrix = partitionsLeaderMatrix.matrix; assertThat(matrix).hasSize(2); assertThat(matrix[0]).hasSize(1); assertThat(matrix[1]).hasSize(1); assertThat(matrix[0]).containsExactly(LEADER); assertThat(matrix[1]).containsExactly(LEADER); }
@Test public void shouldThrowExceptionOnNegativePartitionsCount() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Partitions count must not be smaller then one."); // when new PartitionsLeaderMatrix(-1, 1, 1); }
@Test public void shouldThrowExceptionOnZeroClusterSize() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Cluster size must not be smaller then one."); // when new PartitionsLeaderMatrix(1, 0, 1); }
@Test public void shouldThrowExceptionOnNegativeClusterSize() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Cluster size must not be smaller then one."); // when new PartitionsLeaderMatrix(1, -1, 1); }
@Test public void shouldThrowExceptionOnZeroReplicationFactor() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Replication factor must not be smaller then one."); // when new PartitionsLeaderMatrix(1, 1, -1); }
@Test public void shouldThrowExceptionOnNegativeReplicationFactor() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Replication factor must not be smaller then one."); // when new PartitionsLeaderMatrix(1, 1, -1); }
public BootstrapPartitions(final BrokerCfg brokerCfg) { this.brokerCfg = brokerCfg; final ClusterCfg cluster = brokerCfg.getCluster(); partitionsLeaderMatrix = new PartitionsLeaderMatrix( cluster.getPartitionsCount(), cluster.getClusterSize(), cluster.getReplicationFactor()); final int nodeId = cluster.getNodeId(); followingPartitions = partitionsLeaderMatrix.getFollowingPartitions(nodeId); leadingPartitions = partitionsLeaderMatrix.getLeadingPartitions(nodeId); }
@Test public void shouldThrowExceptionOnSmallerClusterSizeThenReplicationFactor() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Cluster size must not be smaller then replication factor."); // when new PartitionsLeaderMatrix(1, 1, 2); } }
@Test public void shouldThrowExceptionOnZeroPartitionsCount() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Partitions count must not be smaller then one."); // when new PartitionsLeaderMatrix(0, 1, 1); }
@Test public void shouldThrowExceptionToLargePartitionsCount() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Partitions count must be smaller then maximum partition space of " + Protocol.MAXIMUM_PARTITIONS + "."); // when new PartitionsLeaderMatrix((int) Protocol.MAXIMUM_PARTITIONS, 1, 1); }
@Test public void shouldThrowExceptionOnNegativeReplicationFactor() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Replication factor must not be smaller then one."); // when new PartitionsLeaderMatrix(1, 1, -1); }
@Test public void shouldThrowExceptionOnSmallerClusterSizeThenReplicationFactor() { // expect expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Cluster size must not be smaller then replication factor."); // when new PartitionsLeaderMatrix(1, 1, 2); } }