use of java.util.Collections.emptyList in project kafka by apache.
the class FetcherTest method testReturnCommittedTransactions.
@Test
public void testReturnCommittedTransactions() {
buildFetcher(OffsetResetStrategy.EARLIEST, new ByteArrayDeserializer(), new ByteArrayDeserializer(), Integer.MAX_VALUE, IsolationLevel.READ_COMMITTED);
ByteBuffer buffer = ByteBuffer.allocate(1024);
int currentOffset = 0;
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 kafka by apache.
the class AbstractStickyAssignorTest method testAddRemoveTwoConsumersTwoTopics.
@Test
public void testAddRemoveTwoConsumersTwoTopics() {
List<String> allTopics = topics(topic1, topic2);
Map<String, Integer> partitionsPerTopic = new HashMap<>();
partitionsPerTopic.put(topic1, 3);
partitionsPerTopic.put(topic2, 4);
subscriptions.put(consumer1, new Subscription(allTopics));
subscriptions.put(consumer2, new Subscription(allTopics));
Map<String, List<TopicPartition>> assignment = assignor.assign(partitionsPerTopic, subscriptions);
assertEquals(partitions(tp(topic1, 0), tp(topic1, 2), tp(topic2, 1), tp(topic2, 3)), assignment.get(consumer1));
assertEquals(partitions(tp(topic1, 1), tp(topic2, 0), tp(topic2, 2)), assignment.get(consumer2));
assertTrue(assignor.partitionsTransferringOwnership.isEmpty());
verifyValidityAndBalance(subscriptions, assignment, partitionsPerTopic);
assertTrue(isFullyBalanced(assignment));
// add 2 consumers
subscriptions.put(consumer1, buildSubscription(allTopics, assignment.get(consumer1)));
subscriptions.put(consumer2, buildSubscription(allTopics, assignment.get(consumer2)));
subscriptions.put(consumer3, buildSubscription(allTopics, Collections.emptyList()));
subscriptions.put(consumer4, buildSubscription(allTopics, Collections.emptyList()));
assignment = assignor.assign(partitionsPerTopic, subscriptions);
Map<TopicPartition, String> expectedPartitionsTransferringOwnership = new HashMap<>();
expectedPartitionsTransferringOwnership.put(tp(topic2, 1), consumer3);
expectedPartitionsTransferringOwnership.put(tp(topic2, 3), consumer3);
expectedPartitionsTransferringOwnership.put(tp(topic2, 2), consumer4);
assertEquals(expectedPartitionsTransferringOwnership, assignor.partitionsTransferringOwnership);
verifyValidityAndBalance(subscriptions, assignment, partitionsPerTopic);
assertEquals(partitions(tp(topic1, 0), tp(topic1, 2)), assignment.get(consumer1));
assertEquals(partitions(tp(topic1, 1), tp(topic2, 0)), assignment.get(consumer2));
assertEquals(partitions(tp(topic2, 1), tp(topic2, 3)), assignment.get(consumer3));
assertEquals(partitions(tp(topic2, 2)), assignment.get(consumer4));
assertTrue(isFullyBalanced(assignment));
// remove 2 consumers
subscriptions.remove(consumer1);
subscriptions.remove(consumer2);
subscriptions.put(consumer3, buildSubscription(allTopics, assignment.get(consumer3)));
subscriptions.put(consumer4, buildSubscription(allTopics, assignment.get(consumer4)));
assignment = assignor.assign(partitionsPerTopic, subscriptions);
assertEquals(partitions(tp(topic2, 1), tp(topic2, 3), tp(topic1, 0), tp(topic2, 0)), assignment.get(consumer3));
assertEquals(partitions(tp(topic2, 2), tp(topic1, 1), tp(topic1, 2)), assignment.get(consumer4));
assertTrue(assignor.partitionsTransferringOwnership.isEmpty());
verifyValidityAndBalance(subscriptions, assignment, partitionsPerTopic);
assertTrue(isFullyBalanced(assignment));
}
use of java.util.Collections.emptyList in project crate by crate.
the class NodeJoinTests method setupMasterServiceAndCoordinator.
private void setupMasterServiceAndCoordinator(long term, ClusterState initialState, MasterService masterService, ThreadPool threadPool, Random random) {
if (this.masterService != null || coordinator != null) {
throw new IllegalStateException("method setupMasterServiceAndCoordinator can only be called once");
}
this.masterService = masterService;
CapturingTransport capturingTransport = new CapturingTransport() {
@Override
protected void onSendRequest(long requestId, String action, TransportRequest request, DiscoveryNode destination) {
if (action.equals(HANDSHAKE_ACTION_NAME)) {
handleResponse(requestId, new TransportService.HandshakeResponse(destination, initialState.getClusterName(), destination.getVersion()));
} else if (action.equals(JoinHelper.VALIDATE_JOIN_ACTION_NAME)) {
handleResponse(requestId, new TransportResponse.Empty());
} else {
super.onSendRequest(requestId, action, request, destination);
}
}
};
final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
TransportService transportService = capturingTransport.createTransportService(Settings.EMPTY, threadPool, x -> initialState.nodes().getLocalNode(), clusterSettings);
coordinator = new Coordinator("test_node", Settings.EMPTY, clusterSettings, transportService, writableRegistry(), ESAllocationTestCase.createAllocationService(Settings.EMPTY), masterService, () -> new InMemoryPersistedState(term, initialState), r -> emptyList(), new NoOpClusterApplier(), Collections.emptyList(), random, (s, p, r) -> {
});
transportService.start();
transportService.acceptIncomingRequests();
transport = capturingTransport;
coordinator.start();
coordinator.startInitialJoin();
}
use of java.util.Collections.emptyList in project open-kilda by telstra.
the class InMemoryPathComputer method getNPaths.
@Override
public List<Path> getNPaths(SwitchId srcSwitchId, SwitchId dstSwitchId, int count, FlowEncapsulationType flowEncapsulationType, PathComputationStrategy pathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) throws RecoverableException, UnroutableFlowException {
final long maxLatencyNs = maxLatency != null ? maxLatency.toNanos() : 0;
final long maxLatencyTier2Ns = maxLatencyTier2 != null ? maxLatencyTier2.toNanos() : 0;
Flow flow = Flow.builder().flowId(// just any id, as not used.
"").srcSwitch(Switch.builder().switchId(srcSwitchId).build()).destSwitch(Switch.builder().switchId(dstSwitchId).build()).ignoreBandwidth(false).encapsulationType(flowEncapsulationType).bandwidth(// to get ISLs with non zero available bandwidth
1).maxLatency(maxLatencyNs).maxLatencyTier2(maxLatencyTier2Ns).build();
AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
if (MAX_LATENCY.equals(pathComputationStrategy) && (flow.getMaxLatency() == null || flow.getMaxLatency() == 0)) {
pathComputationStrategy = LATENCY;
}
List<List<Edge>> paths;
switch(pathComputationStrategy) {
case COST:
case LATENCY:
case COST_AND_AVAILABLE_BANDWIDTH:
paths = pathFinder.findNPathsBetweenSwitches(availableNetwork, srcSwitchId, dstSwitchId, count, getWeightFunctionByStrategy(pathComputationStrategy));
break;
case MAX_LATENCY:
paths = pathFinder.findNPathsBetweenSwitches(availableNetwork, srcSwitchId, dstSwitchId, count, getWeightFunctionByStrategy(pathComputationStrategy), maxLatencyNs, maxLatencyTier2Ns);
break;
default:
throw new UnsupportedOperationException(String.format("Unsupported strategy type %s", pathComputationStrategy));
}
Comparator<Path> comparator;
if (pathComputationStrategy == LATENCY || pathComputationStrategy == MAX_LATENCY) {
comparator = Comparator.comparing(Path::getLatency).thenComparing(Comparator.comparing(Path::getMinAvailableBandwidth).reversed());
} else {
comparator = Comparator.comparing(Path::getMinAvailableBandwidth).reversed().thenComparing(Path::getLatency);
}
return paths.stream().map(edges -> convertToPath(srcSwitchId, dstSwitchId, edges)).sorted(comparator).limit(count).collect(Collectors.toList());
}
use of java.util.Collections.emptyList in project kafka by apache.
the class ConsumerCoordinatorTest method testNormalJoinGroupLeader.
@Test
public void testNormalJoinGroupLeader() {
final String consumerId = "leader";
final Set<String> subscription = singleton(topic1);
final List<TopicPartition> owned = Collections.emptyList();
final List<TopicPartition> assigned = Arrays.asList(t1p);
subscriptions.subscribe(singleton(topic1), rebalanceListener);
// ensure metadata is up-to-date for leader
client.updateMetadata(metadataResponse);
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady(time.timer(Long.MAX_VALUE));
// normal join group
Map<String, List<String>> memberSubscriptions = singletonMap(consumerId, singletonList(topic1));
partitionAssignor.prepare(singletonMap(consumerId, assigned));
client.prepareResponse(joinGroupLeaderResponse(1, consumerId, memberSubscriptions, Errors.NONE));
client.prepareResponse(body -> {
SyncGroupRequest sync = (SyncGroupRequest) body;
return sync.data().memberId().equals(consumerId) && sync.data().generationId() == 1 && sync.groupAssignments().containsKey(consumerId);
}, syncGroupResponse(assigned, Errors.NONE));
coordinator.poll(time.timer(Long.MAX_VALUE));
assertFalse(coordinator.rejoinNeededOrPending());
assertEquals(toSet(assigned), subscriptions.assignedPartitions());
assertEquals(subscription, subscriptions.metadataTopics());
assertEquals(0, rebalanceListener.revokedCount);
assertNull(rebalanceListener.revoked);
assertEquals(1, rebalanceListener.assignedCount);
assertEquals(getAdded(owned, assigned), rebalanceListener.assigned);
}
Aggregations