use of org.junit.jupiter.params.provider.ValueSource in project kafka by apache.
the class SnapshotsTest method testDeleteSnapshot.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testDeleteSnapshot(boolean renameBeforeDeleting) throws IOException {
OffsetAndEpoch snapshotId = new OffsetAndEpoch(TestUtils.RANDOM.nextInt(Integer.MAX_VALUE), TestUtils.RANDOM.nextInt(Integer.MAX_VALUE));
Path logDirPath = TestUtils.tempDirectory().toPath();
try (FileRawSnapshotWriter snapshot = FileRawSnapshotWriter.create(logDirPath, snapshotId, Optional.empty())) {
snapshot.freeze();
Path snapshotPath = Snapshots.snapshotPath(logDirPath, snapshotId);
assertTrue(Files.exists(snapshotPath));
if (renameBeforeDeleting)
// rename snapshot before deleting
Utils.atomicMoveWithFallback(snapshotPath, Snapshots.deleteRename(snapshotPath, snapshotId), false);
assertTrue(Snapshots.deleteIfExists(logDirPath, snapshot.snapshotId()));
assertFalse(Files.exists(snapshotPath));
assertFalse(Files.exists(Snapshots.deleteRename(snapshotPath, snapshotId)));
}
}
use of org.junit.jupiter.params.provider.ValueSource in project kafka by apache.
the class TransactionsCommandTest method testOldBrokerAbortTransactionWithUnknownCoordinatorEpoch.
@ParameterizedTest
@ValueSource(ints = { 29, -1 })
public void testOldBrokerAbortTransactionWithUnknownCoordinatorEpoch(int coordinatorEpoch) throws Exception {
TopicPartition topicPartition = new TopicPartition("foo", 5);
long producerId = 12345L;
short producerEpoch = 15;
String[] args = new String[] { "--bootstrap-server", "localhost:9092", "abort", "--topic", topicPartition.topic(), "--partition", String.valueOf(topicPartition.partition()), "--producer-id", String.valueOf(producerId), "--producer-epoch", String.valueOf(producerEpoch), "--coordinator-epoch", String.valueOf(coordinatorEpoch) };
AbortTransactionResult abortTransactionResult = Mockito.mock(AbortTransactionResult.class);
KafkaFuture<Void> abortFuture = completedFuture(null);
final int expectedCoordinatorEpoch;
if (coordinatorEpoch < 0) {
expectedCoordinatorEpoch = 0;
} else {
expectedCoordinatorEpoch = coordinatorEpoch;
}
AbortTransactionSpec expectedAbortSpec = new AbortTransactionSpec(topicPartition, producerId, producerEpoch, expectedCoordinatorEpoch);
Mockito.when(abortTransactionResult.all()).thenReturn(abortFuture);
Mockito.when(admin.abortTransaction(expectedAbortSpec)).thenReturn(abortTransactionResult);
execute(args);
assertNormalExit();
}
use of org.junit.jupiter.params.provider.ValueSource in project kafka by apache.
the class ReplicationControlManagerTest method testElectUncleanLeaders.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testElectUncleanLeaders(boolean electAllPartitions) throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext();
ReplicationControlManager replication = ctx.replicationControl;
ctx.registerBrokers(0, 1, 2, 3, 4);
ctx.unfenceBrokers(0, 1, 2, 3, 4);
Uuid fooId = ctx.createTestTopic("foo", new int[][] { new int[] { 1, 2, 3 }, new int[] { 2, 3, 4 }, new int[] { 0, 2, 1 } }).topicId();
TopicIdPartition partition0 = new TopicIdPartition(fooId, 0);
TopicIdPartition partition1 = new TopicIdPartition(fooId, 1);
TopicIdPartition partition2 = new TopicIdPartition(fooId, 2);
ctx.fenceBrokers(Utils.mkSet(2, 3));
ctx.fenceBrokers(Utils.mkSet(1, 2, 3));
assertLeaderAndIsr(replication, partition0, NO_LEADER, new int[] { 1 });
assertLeaderAndIsr(replication, partition1, 4, new int[] { 4 });
assertLeaderAndIsr(replication, partition2, 0, new int[] { 0 });
ElectLeadersRequestData request = buildElectLeadersRequest(ElectionType.UNCLEAN, electAllPartitions ? null : singletonMap("foo", asList(0, 1, 2)));
// No election can be done yet because no replicas are available for partition 0
ControllerResult<ElectLeadersResponseData> result1 = replication.electLeaders(request);
assertEquals(Collections.emptyList(), result1.records());
ElectLeadersResponseData expectedResponse1 = buildElectLeadersResponse(NONE, electAllPartitions, Utils.mkMap(Utils.mkEntry(new TopicPartition("foo", 0), new ApiError(ELIGIBLE_LEADERS_NOT_AVAILABLE)), Utils.mkEntry(new TopicPartition("foo", 1), new ApiError(ELECTION_NOT_NEEDED)), Utils.mkEntry(new TopicPartition("foo", 2), new ApiError(ELECTION_NOT_NEEDED))));
assertElectLeadersResponse(expectedResponse1, result1.response());
// Now we bring 2 back online which should allow the unclean election of partition 0
ctx.unfenceBrokers(Utils.mkSet(2));
// Bring 2 back into the ISR for partition 1. This allows us to verify that
// preferred election does not occur as a result of the unclean election request.
ctx.alterIsr(partition1, 4, asList(2, 4));
ControllerResult<ElectLeadersResponseData> result = replication.electLeaders(request);
assertEquals(1, result.records().size());
ApiMessageAndVersion record = result.records().get(0);
assertTrue(record.message() instanceof PartitionChangeRecord);
PartitionChangeRecord partitionChangeRecord = (PartitionChangeRecord) record.message();
assertEquals(0, partitionChangeRecord.partitionId());
assertEquals(2, partitionChangeRecord.leader());
assertEquals(singletonList(2), partitionChangeRecord.isr());
ctx.replay(result.records());
assertLeaderAndIsr(replication, partition0, 2, new int[] { 2 });
assertLeaderAndIsr(replication, partition1, 4, new int[] { 2, 4 });
assertLeaderAndIsr(replication, partition2, 0, new int[] { 0 });
ElectLeadersResponseData expectedResponse = buildElectLeadersResponse(NONE, electAllPartitions, Utils.mkMap(Utils.mkEntry(new TopicPartition("foo", 0), ApiError.NONE), Utils.mkEntry(new TopicPartition("foo", 1), new ApiError(ELECTION_NOT_NEEDED)), Utils.mkEntry(new TopicPartition("foo", 2), new ApiError(ELECTION_NOT_NEEDED))));
assertElectLeadersResponse(expectedResponse, result.response());
}
use of org.junit.jupiter.params.provider.ValueSource in project kafka by apache.
the class ClusterControlManagerTest method testPlaceReplicas.
@ParameterizedTest
@ValueSource(ints = { 3, 10 })
public void testPlaceReplicas(int numUsableBrokers) throws Exception {
MockTime time = new MockTime(0, 0, 0);
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
MockRandom random = new MockRandom();
ClusterControlManager clusterControl = new ClusterControlManager(new LogContext(), Uuid.randomUuid().toString(), time, snapshotRegistry, 1000, new StripedReplicaPlacer(random), new MockControllerMetrics());
clusterControl.activate();
for (int i = 0; i < numUsableBrokers; i++) {
RegisterBrokerRecord brokerRecord = new RegisterBrokerRecord().setBrokerEpoch(100).setBrokerId(i);
brokerRecord.endPoints().add(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9092).setName("PLAINTEXT").setHost("example.com"));
clusterControl.replay(brokerRecord);
UnfenceBrokerRecord unfenceRecord = new UnfenceBrokerRecord().setId(i).setEpoch(100);
clusterControl.replay(unfenceRecord);
clusterControl.heartbeatManager().touch(i, false, 0);
}
for (int i = 0; i < numUsableBrokers; i++) {
assertTrue(clusterControl.unfenced(i), String.format("broker %d was not unfenced.", i));
}
for (int i = 0; i < 100; i++) {
List<List<Integer>> results = clusterControl.placeReplicas(0, 1, (short) 3);
HashSet<Integer> seen = new HashSet<>();
for (Integer result : results.get(0)) {
assertTrue(result >= 0);
assertTrue(result < numUsableBrokers);
assertTrue(seen.add(result));
}
}
}
use of org.junit.jupiter.params.provider.ValueSource in project zaproxy by zaproxy.
the class ScriptsPassiveScannerUnitTest method shouldHandleScriptsThatDoNotImplementAppliesToHistoryType.
@ParameterizedTest
@ValueSource(ints = { 1, 2, 10, 15 })
void shouldHandleScriptsThatDoNotImplementAppliesToHistoryType(int historyType) throws Exception {
// Given
PassiveScript script = mock(TARGET_INTERFACE);
NoSuchMethodException cause = mock(NoSuchMethodException.class);
given(cause.getMessage()).willReturn("appliesToHistoryType");
UndeclaredThrowableException exception = mock(UndeclaredThrowableException.class);
given(exception.getCause()).willReturn(cause);
given(script.appliesToHistoryType(anyInt())).willThrow(exception);
ScriptsCache<PassiveScript> scriptsCache = createScriptsCache(createCachedScript(script));
given(extensionScript.<PassiveScript>createScriptsCache(any())).willReturn(scriptsCache);
ScriptsPassiveScanner scriptsPassiveScanner = new ScriptsPassiveScanner();
scriptsPassiveScanner.appliesToHistoryType(historyType);
// When
scriptsPassiveScanner.scanHttpResponseReceive(message, id, source);
// Then
verify(script, times(1)).appliesToHistoryType(historyType);
verify(script, times(1)).scan(any(), any(), any());
}
Aggregations