Search in sources :

Example 1 with ContainerExecException

use of org.apache.pulsar.tests.integration.docker.ContainerExecException in project pulsar by apache.

the class TenantTest method testCreateExistTenantCmd.

@Test
public void testCreateExistTenantCmd() {
    ContainerExecException ex = expectThrows(ContainerExecException.class, () -> pulsarCluster.runAdminCommandOnAnyBroker("tenants", "create", "public"));
    assertTrue(ex.getResult().getStderr().contains("Tenant already exist"));
}
Also used : ContainerExecException(org.apache.pulsar.tests.integration.docker.ContainerExecException) Test(org.testng.annotations.Test)

Example 2 with ContainerExecException

use of org.apache.pulsar.tests.integration.docker.ContainerExecException in project pulsar by apache.

the class PulsarFunctionsTest method checkPublisherCleanup.

private void checkPublisherCleanup(String topic) throws Exception {
    try {
        ContainerExecResult result = pulsarCluster.getAnyBroker().execCmd(PulsarCluster.ADMIN_SCRIPT, "topics", "stats", topic);
        TopicStats topicStats = ObjectMapperFactory.getThreadLocal().readValue(result.getStdout(), TopicStats.class);
        assertEquals(topicStats.getPublishers().size(), 0);
    } catch (ContainerExecException e) {
        fail("Command should have exited with non-zero");
    }
}
Also used : ContainerExecException(org.apache.pulsar.tests.integration.docker.ContainerExecException) ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult) TopicStats(org.apache.pulsar.common.policies.data.TopicStats)

Example 3 with ContainerExecException

use of org.apache.pulsar.tests.integration.docker.ContainerExecException in project pulsar by apache.

the class TestPulsarSQLBase method waitPulsarSQLReady.

public void waitPulsarSQLReady() throws Exception {
    // wait until presto worker started
    ContainerExecResult result;
    do {
        try {
            result = execQuery("show catalogs;");
            assertThat(result.getExitCode()).isEqualTo(0);
            assertThat(result.getStdout()).contains("pulsar", "system");
            break;
        } catch (ContainerExecException cee) {
            if (cee.getResult().getStderr().contains("Presto server is still initializing")) {
                Thread.sleep(10000);
            } else {
                throw cee;
            }
        }
    } while (true);
    // check presto follow workers start finish.
    if (pulsarCluster.getSqlFollowWorkerContainers() != null && pulsarCluster.getSqlFollowWorkerContainers().size() > 0) {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder().url("http://" + pulsarCluster.getPrestoWorkerContainer().getUrl() + "/v1/node").build();
        do {
            try (Response response = okHttpClient.newCall(request).execute()) {
                Assert.assertNotNull(response.body());
                String nodeJsonStr = response.body().string();
                Assert.assertTrue(nodeJsonStr.length() > 0);
                log.info("presto node info: {}", nodeJsonStr);
                if (nodeJsonStr.contains("uri")) {
                    log.info("presto node exist.");
                    break;
                }
                Thread.sleep(1000);
            }
        } while (true);
    }
}
Also used : Response(org.testcontainers.shaded.okhttp3.Response) ContainerExecException(org.apache.pulsar.tests.integration.docker.ContainerExecException) OkHttpClient(org.testcontainers.shaded.okhttp3.OkHttpClient) Request(org.testcontainers.shaded.okhttp3.Request) ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult)

Example 4 with ContainerExecException

use of org.apache.pulsar.tests.integration.docker.ContainerExecException in project pulsar by apache.

the class CLITest method testGetTopicListCommand.

@Test
public void testGetTopicListCommand() throws Exception {
    ContainerExecResult result;
    final String namespaceLocalName = "list-topics-" + randomName(8);
    result = pulsarCluster.createNamespace(namespaceLocalName);
    final String namespace = "public/" + namespaceLocalName;
    assertEquals(0, result.getExitCode());
    PulsarClient client = PulsarClient.builder().serviceUrl(pulsarCluster.getPlainTextServiceUrl()).build();
    final String persistentTopicName = TopicName.get("persistent", NamespaceName.get(namespace), "get_topics_mode_" + UUID.randomUUID().toString()).toString();
    final String nonPersistentTopicName = TopicName.get("non-persistent", NamespaceName.get(namespace), "get_topics_mode_" + UUID.randomUUID().toString()).toString();
    Producer<byte[]> producer1 = client.newProducer().topic(persistentTopicName).create();
    Producer<byte[]> producer2 = client.newProducer().topic(nonPersistentTopicName).create();
    BrokerContainer container = pulsarCluster.getAnyBroker();
    result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "topics", "list", namespace);
    assertTrue(result.getStdout().contains(persistentTopicName));
    assertTrue(result.getStdout().contains(nonPersistentTopicName));
    result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "topics", "list", "--topic-domain", "persistent", namespace);
    assertTrue(result.getStdout().contains(persistentTopicName));
    assertFalse(result.getStdout().contains(nonPersistentTopicName));
    result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "topics", "list", "--topic-domain", "non_persistent", namespace);
    assertFalse(result.getStdout().contains(persistentTopicName));
    assertTrue(result.getStdout().contains(nonPersistentTopicName));
    try {
        container.execCmd(PulsarCluster.ADMIN_SCRIPT, "topics", "list", "--topic-domain", "none", namespace);
        fail();
    } catch (ContainerExecException ignore) {
    }
    producer1.close();
    producer2.close();
}
Also used : ContainerExecException(org.apache.pulsar.tests.integration.docker.ContainerExecException) ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult) PulsarClient(org.apache.pulsar.client.api.PulsarClient) BrokerContainer(org.apache.pulsar.tests.integration.containers.BrokerContainer) Test(org.testng.annotations.Test)

Example 5 with ContainerExecException

use of org.apache.pulsar.tests.integration.docker.ContainerExecException in project pulsar by apache.

the class CLITest method testPropertiesCLI.

@Test
public void testPropertiesCLI() throws Exception {
    final BrokerContainer container = pulsarCluster.getAnyBroker();
    final String namespace = "public/default";
    ContainerExecResult result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "namespaces", "set-property", "-k", "a", "-v", "a", namespace);
    assertTrue(result.getStdout().isEmpty());
    result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "namespaces", "get-property", "-k", "a", namespace);
    assertTrue(result.getStdout().contains("a"));
    result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "namespaces", "remove-property", "-k", "a", namespace);
    assertTrue(result.getStdout().contains("a"));
    result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "namespaces", "remove-property", "-k", "a", namespace);
    assertTrue(result.getStdout().contains("null"));
    result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "namespaces", "set-properties", "-p", "a=a,b=b,c=c", namespace);
    assertTrue(result.getStdout().isEmpty());
    result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "namespaces", "get-properties", namespace);
    assertFalse(result.getStdout().isEmpty());
    result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "namespaces", "clear-properties", namespace);
    assertTrue(result.getStdout().isEmpty());
    try {
        container.execCmd(PulsarCluster.ADMIN_SCRIPT, "bookies", "set-bookie-rack", "-b", "localhost:8082", "-r", "");
        fail("Command should have exited with non-zero");
    } catch (ContainerExecException e) {
        assertEquals(e.getResult().getStderr(), "rack name is invalid, it should not be null, empty or '/'\n\n");
    }
    try {
        container.execCmd(PulsarCluster.ADMIN_SCRIPT, "namespaces", "set-schema-autoupdate-strategy", namespace);
    } catch (ContainerExecException e) {
        assertEquals(e.getResult().getStderr(), "Either --compatibility or --disabled must be specified\n\n");
    }
}
Also used : ContainerExecException(org.apache.pulsar.tests.integration.docker.ContainerExecException) ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult) BrokerContainer(org.apache.pulsar.tests.integration.containers.BrokerContainer) Test(org.testng.annotations.Test)

Aggregations

ContainerExecException (org.apache.pulsar.tests.integration.docker.ContainerExecException)41 ContainerExecResult (org.apache.pulsar.tests.integration.docker.ContainerExecResult)26 Test (org.testng.annotations.Test)26 BrokerContainer (org.apache.pulsar.tests.integration.containers.BrokerContainer)15 TopicStats (org.apache.pulsar.common.policies.data.TopicStats)6 InspectExecResponse (com.github.dockerjava.api.command.InspectExecResponse)3 Frame (com.github.dockerjava.api.model.Frame)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Closeable (java.io.Closeable)3 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 PulsarClient (org.apache.pulsar.client.api.PulsarClient)3 TopicName (org.apache.pulsar.common.naming.TopicName)3 ContainerExecResultBytes (org.apache.pulsar.tests.integration.docker.ContainerExecResultBytes)3 OkHttpClient (org.testcontainers.shaded.okhttp3.OkHttpClient)3 Request (org.testcontainers.shaded.okhttp3.Request)3 Response (org.testcontainers.shaded.okhttp3.Response)3