Search in sources :

Example 41 with ValueSource

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)));
    }
}
Also used : OffsetAndEpoch(org.apache.kafka.raft.OffsetAndEpoch) Path(java.nio.file.Path) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 42 with ValueSource

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();
}
Also used : AbortTransactionSpec(org.apache.kafka.clients.admin.AbortTransactionSpec) TopicPartition(org.apache.kafka.common.TopicPartition) AbortTransactionResult(org.apache.kafka.clients.admin.AbortTransactionResult) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with ValueSource

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());
}
Also used : Uuid(org.apache.kafka.common.Uuid) PartitionChangeRecord(org.apache.kafka.common.metadata.PartitionChangeRecord) TopicPartition(org.apache.kafka.common.TopicPartition) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ElectLeadersResponseData(org.apache.kafka.common.message.ElectLeadersResponseData) TopicIdPartition(org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition) ApiError(org.apache.kafka.common.requests.ApiError) ElectLeadersRequestData(org.apache.kafka.common.message.ElectLeadersRequestData) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with ValueSource

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));
        }
    }
}
Also used : LogContext(org.apache.kafka.common.utils.LogContext) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) List(java.util.List) UnfenceBrokerRecord(org.apache.kafka.common.metadata.UnfenceBrokerRecord) MockTime(org.apache.kafka.common.utils.MockTime) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 45 with ValueSource

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());
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) PassiveScript(org.zaproxy.zap.extension.pscan.PassiveScript) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)266 ValueSource (org.junit.jupiter.params.provider.ValueSource)266 HashSet (java.util.HashSet)23 HistogramTestUtils.constructDoubleHistogram (org.HdrHistogram.HistogramTestUtils.constructDoubleHistogram)23 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)20 ApiResponse (org.hisp.dhis.dto.ApiResponse)15 UpdateModel (com.synopsys.integration.alert.update.model.UpdateModel)13 File (java.io.File)13 List (java.util.List)13 OffsetDateTime (java.time.OffsetDateTime)10 Map (java.util.Map)10 TimeUnit (java.util.concurrent.TimeUnit)10 TopicPartition (org.apache.kafka.common.TopicPartition)9 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)8 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)8 ZooKeeper (org.apache.zookeeper.ZooKeeper)8 JsonObject (com.google.gson.JsonObject)7 IOException (java.io.IOException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7