use of org.apache.kafka.common.message.BrokerHeartbeatRequestData in project kafka by apache.
the class QuorumControllerTest method testSnapshotOnlyAfterConfiguredMinBytes.
@Test
public void testSnapshotOnlyAfterConfiguredMinBytes() throws Throwable {
final int numBrokers = 4;
final int maxNewRecordBytes = 1000;
Map<Integer, Long> brokerEpochs = new HashMap<>();
try (LocalLogManagerTestEnv logEnv = new LocalLogManagerTestEnv(3, Optional.empty())) {
try (QuorumControllerTestEnv controlEnv = new QuorumControllerTestEnv(logEnv, builder -> builder.setConfigDefs(CONFIGS).setSnapshotMaxNewRecordBytes(maxNewRecordBytes))) {
QuorumController active = controlEnv.activeController();
for (int i = 0; i < numBrokers; i++) {
BrokerRegistrationReply reply = active.registerBroker(new BrokerRegistrationRequestData().setBrokerId(i).setRack(null).setClusterId(active.clusterId()).setIncarnationId(Uuid.fromString("kxAT73dKQsitIedpiPtwB" + i)).setListeners(new ListenerCollection(Arrays.asList(new Listener().setName("PLAINTEXT").setHost("localhost").setPort(9092 + i)).iterator()))).get();
brokerEpochs.put(i, reply.epoch());
assertEquals(new BrokerHeartbeatReply(true, false, false, false), active.processBrokerHeartbeat(new BrokerHeartbeatRequestData().setWantFence(false).setBrokerEpoch(brokerEpochs.get(i)).setBrokerId(i).setCurrentMetadataOffset(100000L)).get());
}
assertTrue(logEnv.appendedBytes() < maxNewRecordBytes, String.format("%s appended bytes is not less than %s max new record bytes", logEnv.appendedBytes(), maxNewRecordBytes));
// Keep creating topic until we reached the max bytes limit
int counter = 0;
while (logEnv.appendedBytes() < maxNewRecordBytes) {
counter += 1;
String topicName = String.format("foo-%s", counter);
active.createTopics(new CreateTopicsRequestData().setTopics(new CreatableTopicCollection(Collections.singleton(new CreatableTopic().setName(topicName).setNumPartitions(-1).setReplicationFactor((short) -1).setAssignments(new CreatableReplicaAssignmentCollection(Arrays.asList(new CreatableReplicaAssignment().setPartitionIndex(0).setBrokerIds(Arrays.asList(0, 1, 2)), new CreatableReplicaAssignment().setPartitionIndex(1).setBrokerIds(Arrays.asList(1, 2, 0))).iterator()))).iterator()))).get();
}
logEnv.waitForLatestSnapshot();
}
}
}
use of org.apache.kafka.common.message.BrokerHeartbeatRequestData in project kafka by apache.
the class BrokerHeartbeatManagerTest method testCalculateNextBrokerState.
@Test
public void testCalculateNextBrokerState() {
BrokerHeartbeatManager manager = newBrokerHeartbeatManager();
manager.touch(0, true, 100);
manager.touch(1, false, 98);
manager.touch(2, false, 100);
manager.touch(3, false, 100);
manager.touch(4, true, 100);
manager.touch(5, false, 99);
manager.updateControlledShutdownOffset(5, 99);
assertEquals(98L, manager.lowestActiveOffset());
assertEquals(new BrokerControlStates(FENCED, SHUTDOWN_NOW), manager.calculateNextBrokerState(0, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> false));
assertEquals(new BrokerControlStates(FENCED, UNFENCED), manager.calculateNextBrokerState(0, new BrokerHeartbeatRequestData().setWantFence(false).setCurrentMetadataOffset(100), 100, () -> false));
assertEquals(new BrokerControlStates(FENCED, FENCED), manager.calculateNextBrokerState(0, new BrokerHeartbeatRequestData().setWantFence(false).setCurrentMetadataOffset(50), 100, () -> false));
assertEquals(new BrokerControlStates(FENCED, FENCED), manager.calculateNextBrokerState(0, new BrokerHeartbeatRequestData().setWantFence(true), 100, () -> false));
assertEquals(new BrokerControlStates(UNFENCED, CONTROLLED_SHUTDOWN), manager.calculateNextBrokerState(1, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> true));
assertEquals(new BrokerControlStates(UNFENCED, SHUTDOWN_NOW), manager.calculateNextBrokerState(1, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> false));
assertEquals(new BrokerControlStates(UNFENCED, UNFENCED), manager.calculateNextBrokerState(1, new BrokerHeartbeatRequestData().setWantFence(false), 100, () -> false));
assertEquals(new BrokerControlStates(CONTROLLED_SHUTDOWN, CONTROLLED_SHUTDOWN), manager.calculateNextBrokerState(5, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> true));
assertEquals(new BrokerControlStates(CONTROLLED_SHUTDOWN, CONTROLLED_SHUTDOWN), manager.calculateNextBrokerState(5, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> false));
manager.fence(1);
assertEquals(new BrokerControlStates(CONTROLLED_SHUTDOWN, SHUTDOWN_NOW), manager.calculateNextBrokerState(5, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> false));
assertEquals(new BrokerControlStates(CONTROLLED_SHUTDOWN, CONTROLLED_SHUTDOWN), manager.calculateNextBrokerState(5, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> true));
}
Aggregations