use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class PartitionRegistrationTest method testRecordRoundTrip.
@Test
public void testRecordRoundTrip() {
PartitionRegistration registrationA = new PartitionRegistration(new int[] { 1, 2, 3 }, new int[] { 1, 2 }, new int[] { 1 }, Replicas.NONE, 1, 0, 0);
Uuid topicId = Uuid.fromString("OGdAI5nxT_m-ds3rJMqPLA");
int partitionId = 4;
ApiMessageAndVersion record = registrationA.toRecord(topicId, partitionId);
PartitionRegistration registrationB = new PartitionRegistration((PartitionRecord) record.message());
assertEquals(registrationA, registrationB);
}
use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class TopicsImageTest method testDeleteAfterChanges.
@Test
public void testDeleteAfterChanges() {
int localId = 3;
Uuid zooId = Uuid.fromString("0hHJ3X5ZQ-CFfQ5xgpj90w");
List<TopicImage> topics = new ArrayList<>();
topics.add(newTopicImage("zoo", zooId, newPartition(new int[] { localId, 1, 2 })));
TopicsImage image = new TopicsImage(newTopicsByIdMap(topics), newTopicsByNameMap(topics));
List<ApiMessageAndVersion> topicRecords = new ArrayList<>();
// leader to follower
topicRecords.add(new ApiMessageAndVersion(new PartitionChangeRecord().setTopicId(zooId).setPartitionId(0).setLeader(1), PARTITION_CHANGE_RECORD.highestSupportedVersion()));
// remove zoo topic
topicRecords.add(new ApiMessageAndVersion(new RemoveTopicRecord().setTopicId(zooId), REMOVE_TOPIC_RECORD.highestSupportedVersion()));
TopicsDelta delta = new TopicsDelta(image);
RecordTestUtils.replayAll(delta, topicRecords);
LocalReplicaChanges changes = delta.localChanges(localId);
assertEquals(new HashSet<>(Arrays.asList(new TopicPartition("zoo", 0))), changes.deletes());
assertEquals(Collections.emptyMap(), changes.leaders());
assertEquals(Collections.emptyMap(), changes.followers());
}
use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class RecordTestUtils method replayAll.
/**
* Replay a list of records to the metadata delta.
*
* @param delta the metadata delta on which to replay the records
* @param highestOffset highest offset from the list of records
* @param highestEpoch highest epoch from the list of records
* @param recordsAndVersions list of records
*/
public static void replayAll(MetadataDelta delta, long highestOffset, int highestEpoch, List<ApiMessageAndVersion> recordsAndVersions) {
for (ApiMessageAndVersion recordAndVersion : recordsAndVersions) {
ApiMessage record = recordAndVersion.message();
delta.replay(highestOffset, highestEpoch, record);
}
}
use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class RecordTestUtils method replayAll.
/**
* Replay a list of records.
*
* @param target The object to invoke the replay function on.
* @param recordsAndVersions A list of records.
*/
public static void replayAll(Object target, List<ApiMessageAndVersion> recordsAndVersions) {
for (ApiMessageAndVersion recordAndVersion : recordsAndVersions) {
ApiMessage record = recordAndVersion.message();
try {
Method method = target.getClass().getMethod("replay", record.getClass());
method.invoke(target, record);
} catch (NoSuchMethodException e) {
try {
Method method = target.getClass().getMethod("replay", record.getClass(), Optional.class);
method.invoke(target, record, Optional.empty());
} catch (NoSuchMethodException t) {
// ignore
} catch (InvocationTargetException t) {
throw new RuntimeException(t);
} catch (IllegalAccessException t) {
throw new RuntimeException(t);
}
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.
the class ReplicationControlManager method handleBrokerUnregistered.
/**
* Generate the appropriate records to handle a broker being unregistered.
*
* First, we remove this broker from any non-singleton ISR. Then we generate an
* UnregisterBrokerRecord.
*
* @param brokerId The broker id.
* @param brokerEpoch The broker epoch.
* @param records The record list to append to.
*/
void handleBrokerUnregistered(int brokerId, long brokerEpoch, List<ApiMessageAndVersion> records) {
generateLeaderAndIsrUpdates("handleBrokerUnregistered", brokerId, NO_LEADER, records, brokersToIsrs.partitionsWithBrokerInIsr(brokerId));
records.add(new ApiMessageAndVersion(new UnregisterBrokerRecord().setBrokerId(brokerId).setBrokerEpoch(brokerEpoch), UNREGISTER_BROKER_RECORD.highestSupportedVersion()));
}
Aggregations