Search in sources :

Example 11 with Collections.emptyList

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));
}
Also used : HashMap(java.util.HashMap) Collections.emptyList(java.util.Collections.emptyList) ArrayList(java.util.ArrayList) List(java.util.List) Subscription(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.Subscription) Test(org.junit.jupiter.api.Test)

Example 12 with Collections.emptyList

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);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) SimpleRecord(org.apache.kafka.common.record.SimpleRecord) FetchRequest(org.apache.kafka.common.requests.FetchRequest) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) ByteBuffer(java.nio.ByteBuffer) MemoryRecords(org.apache.kafka.common.record.MemoryRecords) Test(org.junit.jupiter.api.Test)

Example 13 with Collections.emptyList

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());
}
Also used : OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ExecutionException(java.util.concurrent.ExecutionException) OFGroupDescStatsRequest(org.projectfloodlight.openflow.protocol.OFGroupDescStatsRequest) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Collections.emptyList (java.util.Collections.emptyList)13 List (java.util.List)13 ArrayList (java.util.ArrayList)12 Collections.singletonList (java.util.Collections.singletonList)9 Test (org.junit.jupiter.api.Test)7 TopicPartition (org.apache.kafka.common.TopicPartition)6 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 ByteBuffer (java.nio.ByteBuffer)3 HashSet (java.util.HashSet)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Arrays.asList (java.util.Arrays.asList)2 Collection (java.util.Collection)2 Random (java.util.Random)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1