use of java.util.Collections.emptyList in project kafka by apache.
the class AbstractStickyAssignorTest method testAddRemoveConsumerOneTopic.
@Test
public void testAddRemoveConsumerOneTopic() {
Map<String, Integer> partitionsPerTopic = new HashMap<>();
partitionsPerTopic.put(topic, 3);
subscriptions.put(consumer1, new Subscription(topics(topic)));
Map<String, List<TopicPartition>> assignment = assignor.assign(partitionsPerTopic, subscriptions);
assertEquals(partitions(tp(topic, 0), tp(topic, 1), tp(topic, 2)), assignment.get(consumer1));
verifyValidityAndBalance(subscriptions, assignment, partitionsPerTopic);
assertTrue(isFullyBalanced(assignment));
subscriptions.put(consumer1, buildSubscription(topics(topic), assignment.get(consumer1)));
subscriptions.put(consumer2, buildSubscription(topics(topic), Collections.emptyList()));
assignment = assignor.assign(partitionsPerTopic, subscriptions);
assertEquals(Collections.singletonMap(tp(topic, 2), consumer2), assignor.partitionsTransferringOwnership);
verifyValidityAndBalance(subscriptions, assignment, partitionsPerTopic);
assertEquals(partitions(tp(topic, 0), tp(topic, 1)), assignment.get(consumer1));
assertEquals(partitions(tp(topic, 2)), assignment.get(consumer2));
assertTrue(isFullyBalanced(assignment));
subscriptions.remove(consumer1);
subscriptions.put(consumer2, buildSubscription(topics(topic), assignment.get(consumer2)));
assignment = assignor.assign(partitionsPerTopic, subscriptions);
assertEquals(new HashSet<>(partitions(tp(topic, 2), tp(topic, 1), tp(topic, 0))), new HashSet<>(assignment.get(consumer2)));
assertTrue(assignor.partitionsTransferringOwnership.isEmpty());
verifyValidityAndBalance(subscriptions, assignment, partitionsPerTopic);
assertTrue(isFullyBalanced(assignment));
}
use of java.util.Collections.emptyList in project kafka by apache.
the class FetcherTest method testEmptyControlBatch.
@Test
public void testEmptyControlBatch() {
buildFetcher(OffsetResetStrategy.EARLIEST, new ByteArrayDeserializer(), new ByteArrayDeserializer(), Integer.MAX_VALUE, IsolationLevel.READ_COMMITTED);
ByteBuffer buffer = ByteBuffer.allocate(1024);
int currentOffset = 1;
// Empty control batch should not cause an exception
DefaultRecordBatch.writeEmptyHeader(buffer, RecordBatch.MAGIC_VALUE_V2, 1L, (short) 0, -1, 0, 0, RecordBatch.NO_PARTITION_LEADER_EPOCH, TimestampType.CREATE_TIME, time.milliseconds(), true, true);
currentOffset += appendTransactionalRecords(buffer, 1L, currentOffset, new SimpleRecord(time.milliseconds(), "key".getBytes(), "value".getBytes()), new SimpleRecord(time.milliseconds(), "key".getBytes(), "value".getBytes()));
commitTransaction(buffer, 1L, currentOffset);
buffer.flip();
MemoryRecords records = MemoryRecords.readableRecords(buffer);
assignFromUser(singleton(tp0));
subscriptions.seek(tp0, 0);
// normal fetch
assertEquals(1, fetcher.sendFetches());
assertFalse(fetcher.hasCompletedFetches());
client.prepareResponse(body -> {
FetchRequest request = (FetchRequest) body;
assertEquals(IsolationLevel.READ_COMMITTED, request.isolationLevel());
return true;
}, fullFetchResponseWithAbortedTransactions(records, Collections.emptyList(), Errors.NONE, 100L, 100L, 0));
consumerClient.poll(time.timer(0));
assertTrue(fetcher.hasCompletedFetches());
Map<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> fetchedRecords = fetchedRecords();
assertTrue(fetchedRecords.containsKey(tp0));
assertEquals(fetchedRecords.get(tp0).size(), 2);
}
use of java.util.Collections.emptyList in project open-kilda by telstra.
the class SwitchManager method dumpGroups.
private List<OFGroupDescStatsEntry> dumpGroups(IOFSwitch sw) {
OFFactory ofFactory = sw.getOFFactory();
OFGroupDescStatsRequest groupRequest = ofFactory.buildGroupDescStatsRequest().build();
List<OFGroupDescStatsReply> replies;
try {
ListenableFuture<List<OFGroupDescStatsReply>> future = sw.writeStatsRequest(groupRequest);
replies = future.get(10, TimeUnit.SECONDS);
} catch (ExecutionException | TimeoutException e) {
logger.error("Could not dump groups on switch {}.", sw.getId(), e);
return Collections.emptyList();
} catch (InterruptedException e) {
logger.error("Could not dump groups on switch {}.", sw.getId(), e);
Thread.currentThread().interrupt();
return Collections.emptyList();
}
return replies.stream().map(OFGroupDescStatsReply::getEntries).flatMap(List::stream).collect(toList());
}
Aggregations