Search in sources :

Example 1 with StreamsResetter

use of kafka.tools.StreamsResetter in project apache-kafka-on-k8s by banzaicloud.

the class AbstractResetIntegrationTest method shouldNotAllowToResetWhenInputTopicAbsent.

public void shouldNotAllowToResetWhenInputTopicAbsent() throws Exception {
    appID = testId + "-not-reset-without-input-topic";
    final String[] parameters = new String[] { "--application-id", appID, "--bootstrap-servers", cluster.bootstrapServers(), "--input-topics", NON_EXISTING_TOPIC, "--execute" };
    final Properties cleanUpConfig = new Properties();
    cleanUpConfig.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, 100);
    cleanUpConfig.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "" + CLEANUP_CONSUMER_TIMEOUT);
    final int exitCode = new StreamsResetter().run(parameters, cleanUpConfig);
    Assert.assertEquals(1, exitCode);
}
Also used : StreamsResetter(kafka.tools.StreamsResetter) Properties(java.util.Properties)

Example 2 with StreamsResetter

use of kafka.tools.StreamsResetter in project apache-kafka-on-k8s by banzaicloud.

the class AbstractResetIntegrationTest method cleanGlobal.

private void cleanGlobal(final boolean withIntermediateTopics, final String resetScenario, final String resetScenarioArg) throws Exception {
    // leaving --zookeeper arg here to ensure tool works if users add it
    final List<String> parameterList = new ArrayList<>(Arrays.asList("--application-id", appID, "--bootstrap-servers", cluster.bootstrapServers(), "--input-topics", INPUT_TOPIC, "--execute"));
    if (withIntermediateTopics) {
        parameterList.add("--intermediate-topics");
        parameterList.add(INTERMEDIATE_USER_TOPIC);
    }
    final Map<String, Object> sslConfig = getClientSslConfig();
    if (sslConfig != null) {
        final File configFile = TestUtils.tempFile();
        final BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
        writer.write(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG + "=SSL\n");
        writer.write(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG + "=" + sslConfig.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG) + "\n");
        writer.write(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG + "=" + ((Password) sslConfig.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG)).value() + "\n");
        writer.close();
        parameterList.add("--config-file");
        parameterList.add(configFile.getAbsolutePath());
    }
    if (resetScenario != null) {
        parameterList.add(resetScenario);
    }
    if (resetScenarioArg != null) {
        parameterList.add(resetScenarioArg);
    }
    final String[] parameters = parameterList.toArray(new String[parameterList.size()]);
    final Properties cleanUpConfig = new Properties();
    cleanUpConfig.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, 100);
    cleanUpConfig.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "" + CLEANUP_CONSUMER_TIMEOUT);
    final int exitCode = new StreamsResetter().run(parameters, cleanUpConfig);
    Assert.assertEquals(0, exitCode);
}
Also used : StreamsResetter(kafka.tools.StreamsResetter) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 3 with StreamsResetter

use of kafka.tools.StreamsResetter in project kafka by apache.

the class AbstractResetIntegrationTest method tryCleanGlobal.

protected boolean tryCleanGlobal(final boolean withIntermediateTopics, final String resetScenario, final String resetScenarioArg, final String appID) throws Exception {
    final List<String> parameterList = new ArrayList<>(Arrays.asList("--application-id", appID, "--bootstrap-servers", cluster.bootstrapServers(), "--input-topics", INPUT_TOPIC));
    if (withIntermediateTopics) {
        parameterList.add("--intermediate-topics");
        parameterList.add(INTERMEDIATE_USER_TOPIC);
    }
    final Map<String, Object> sslConfig = getClientSslConfig();
    if (sslConfig != null) {
        final File configFile = TestUtils.tempFile();
        final BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
        writer.write(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG + "=SSL\n");
        writer.write(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG + "=" + sslConfig.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG) + "\n");
        writer.write(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG + "=" + ((Password) sslConfig.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG)).value() + "\n");
        writer.close();
        parameterList.add("--config-file");
        parameterList.add(configFile.getAbsolutePath());
    }
    if (resetScenario != null) {
        parameterList.add(resetScenario);
    }
    if (resetScenarioArg != null) {
        parameterList.add(resetScenarioArg);
    }
    final String[] parameters = parameterList.toArray(new String[0]);
    final Properties cleanUpConfig = new Properties();
    cleanUpConfig.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, 100);
    cleanUpConfig.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, Integer.toString(CLEANUP_CONSUMER_TIMEOUT));
    return new StreamsResetter().run(parameters, cleanUpConfig) == 0;
}
Also used : StreamsResetter(kafka.tools.StreamsResetter) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 4 with StreamsResetter

use of kafka.tools.StreamsResetter in project kafka by apache.

the class ResetIntegrationTest method shouldNotAllowToResetWhenInputTopicAbsent.

@Test
public void shouldNotAllowToResetWhenInputTopicAbsent() {
    final String appID = IntegrationTestUtils.safeUniqueTestName(getClass(), testName);
    final String[] parameters = new String[] { "--application-id", appID, "--bootstrap-servers", cluster.bootstrapServers(), "--input-topics", NON_EXISTING_TOPIC };
    final Properties cleanUpConfig = new Properties();
    cleanUpConfig.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, 100);
    cleanUpConfig.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, Integer.toString(CLEANUP_CONSUMER_TIMEOUT));
    final int exitCode = new StreamsResetter().run(parameters, cleanUpConfig);
    Assert.assertEquals(1, exitCode);
}
Also used : StreamsResetter(kafka.tools.StreamsResetter) Properties(java.util.Properties) IntegrationTest(org.apache.kafka.test.IntegrationTest) Test(org.junit.Test)

Example 5 with StreamsResetter

use of kafka.tools.StreamsResetter in project kafka by apache.

the class ResetIntegrationTest method shouldNotAllowToResetWhileStreamsIsRunning.

@Test
public void shouldNotAllowToResetWhileStreamsIsRunning() {
    final String appID = IntegrationTestUtils.safeUniqueTestName(getClass(), testName);
    final String[] parameters = new String[] { "--application-id", appID, "--bootstrap-servers", cluster.bootstrapServers(), "--input-topics", NON_EXISTING_TOPIC };
    final Properties cleanUpConfig = new Properties();
    cleanUpConfig.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, 100);
    cleanUpConfig.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, Integer.toString(CLEANUP_CONSUMER_TIMEOUT));
    streamsConfig.put(StreamsConfig.APPLICATION_ID_CONFIG, appID);
    // RUN
    streams = new KafkaStreams(setupTopologyWithoutIntermediateUserTopic(), streamsConfig);
    streams.start();
    final int exitCode = new StreamsResetter().run(parameters, cleanUpConfig);
    Assert.assertEquals(1, exitCode);
    streams.close();
}
Also used : StreamsResetter(kafka.tools.StreamsResetter) KafkaStreams(org.apache.kafka.streams.KafkaStreams) Properties(java.util.Properties) IntegrationTest(org.apache.kafka.test.IntegrationTest) Test(org.junit.Test)

Aggregations

StreamsResetter (kafka.tools.StreamsResetter)13 Properties (java.util.Properties)12 Test (org.junit.Test)6 IntegrationTest (org.apache.kafka.test.IntegrationTest)5 KafkaStreams (org.apache.kafka.streams.KafkaStreams)3 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)1 AdminClient (kafka.admin.AdminClient)1 KeyValue (org.apache.kafka.streams.KeyValue)1