Search in sources :

Example 1 with ContainerExecResult

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

the class PulsarGenericObjectSinkTest method deleteSink.

private void deleteSink(String sinkName) throws Exception {
    ContainerExecResult result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "sinks", "delete", "--tenant", "public", "--namespace", "default", "--name", sinkName);
    assertTrue(result.getStdout().contains("successfully"));
    result.assertNoStderr();
}
Also used : ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult)

Example 2 with ContainerExecResult

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

the class PulsarGenericObjectSinkTest method getSinkInfoSuccess.

private void getSinkInfoSuccess(String sinkName) throws Exception {
    ContainerExecResult result = container.execCmd(PulsarCluster.ADMIN_SCRIPT, "sinks", "get", "--tenant", "public", "--namespace", "default", "--name", sinkName);
    assertTrue(result.getStdout().contains("\"name\": \"" + sinkName + "\""));
}
Also used : ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult)

Example 3 with ContainerExecResult

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

the class PackagesCliTest method testPackagesOperationsWithoutUploadingPackages.

@Test(timeOut = 60000 * 5)
public void testPackagesOperationsWithoutUploadingPackages() throws Exception {
    ContainerExecResult result = runPackagesCommand("list", "--type", "function", "public/default");
    assertEquals(result.getExitCode(), 0);
    result = runPackagesCommand("list-versions", "function://public/default/test");
    assertEquals(result.getExitCode(), 0);
    try {
        result = runPackagesCommand("download", "function://public/default/test@v1", "--path", "test-admin");
        fail("this command should be failed");
    } catch (Exception e) {
    // expected exception
    }
}
Also used : ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult) Test(org.testng.annotations.Test)

Example 4 with ContainerExecResult

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

the class SchemaUpdateStrategyTest method testAutoUpdateBackward.

private void testAutoUpdateBackward(String namespace, String topicName) throws Exception {
    ContainerExecResult result = pulsarCluster.runAdminCommandOnAnyBroker("namespaces", "get-schema-autoupdate-strategy", namespace);
    Assert.assertEquals(result.getStdout().trim(), "FULL");
    pulsarCluster.runAdminCommandOnAnyBroker("namespaces", "set-schema-autoupdate-strategy", "--compatibility", "BACKWARD", namespace);
    try (PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(pulsarCluster.getPlainTextServiceUrl()).build()) {
        V1Data v1Data = new V1Data("test1", 1);
        try (Producer<V1Data> p = pulsarClient.newProducer(Schema.AVRO(V1Data.class)).topic(topicName).create()) {
            p.send(v1Data);
        }
        log.info("try with forward compat, should fail");
        try (Producer<V3Data> p = pulsarClient.newProducer(Schema.AVRO(V3Data.class)).topic(topicName).create()) {
            Assert.fail("Forward compat schema should be rejected");
        } catch (PulsarClientException e) {
            Assert.assertTrue(e.getMessage().contains("IncompatibleSchemaException"));
        }
        log.info("try with backward compat, should succeed");
        V2Data v2Data = new V2Data("test2");
        try (Producer<V2Data> p = pulsarClient.newProducer(Schema.AVRO(V2Data.class)).topic(topicName).create()) {
            p.send(v2Data);
        }
        Schema<GenericRecord> schema = Schema.AUTO_CONSUME();
        try (Consumer<GenericRecord> consumer = pulsarClient.newConsumer(schema).topic(topicName).subscriptionInitialPosition(SubscriptionInitialPosition.Earliest).subscriptionName("sub").subscribe()) {
            log.info("Schema Info : {}", schema.getSchemaInfo().getSchemaDefinition());
            Message<GenericRecord> msg1 = consumer.receive();
            v1Data.assertEqualToRecord(msg1.getValue());
            Message<GenericRecord> msg2 = consumer.receive();
            v2Data.assertEqualToRecord(msg2.getValue());
        }
    }
}
Also used : PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult) PulsarClient(org.apache.pulsar.client.api.PulsarClient) GenericRecord(org.apache.pulsar.client.api.schema.GenericRecord)

Example 5 with ContainerExecResult

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

the class SchemaUpdateStrategyTest method testAutoUpdateFull.

private void testAutoUpdateFull(String namespace, String topicName) throws Exception {
    ContainerExecResult result = pulsarCluster.runAdminCommandOnAnyBroker("namespaces", "get-schema-autoupdate-strategy", namespace);
    Assert.assertEquals(result.getStdout().trim(), "FULL");
    try (PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(pulsarCluster.getPlainTextServiceUrl()).build()) {
        V1Data v1Data = new V1Data("test1", 1);
        try (Producer<V1Data> p = pulsarClient.newProducer(Schema.AVRO(V1Data.class)).topic(topicName).create()) {
            p.send(v1Data);
        }
        log.info("try with backward compat only, should fail");
        try (Producer<V2Data> p = pulsarClient.newProducer(Schema.AVRO(V2Data.class)).topic(topicName).create()) {
            Assert.fail("Backward compat only schema should fail");
        } catch (PulsarClientException e) {
            Assert.assertTrue(e.getMessage().contains("IncompatibleSchemaException"));
        }
        log.info("try with forward compat only, should fail");
        try (Producer<V3Data> p = pulsarClient.newProducer(Schema.AVRO(V3Data.class)).topic(topicName).create()) {
            Assert.fail("Forward compat only schema should fail");
        } catch (PulsarClientException e) {
            Assert.assertTrue(e.getMessage().contains("IncompatibleSchemaException"));
        }
        log.info("try with fully compat");
        V4Data v4Data = new V4Data("test2", 1, (short) 100);
        try (Producer<V4Data> p = pulsarClient.newProducer(Schema.AVRO(V4Data.class)).topic(topicName).create()) {
            p.send(v4Data);
        }
        Schema<GenericRecord> schema = Schema.AUTO_CONSUME();
        try (Consumer<GenericRecord> consumer = pulsarClient.newConsumer(schema).topic(topicName).subscriptionName("sub").subscriptionInitialPosition(SubscriptionInitialPosition.Earliest).subscribe()) {
            log.info("Schema Info : {}", schema.getSchemaInfo().getSchemaDefinition());
            Message<GenericRecord> msg1 = consumer.receive();
            v1Data.assertEqualToRecord(msg1.getValue());
            Message<GenericRecord> msg2 = consumer.receive();
            v4Data.assertEqualToRecord(msg2.getValue());
        }
    }
}
Also used : PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult) PulsarClient(org.apache.pulsar.client.api.PulsarClient) GenericRecord(org.apache.pulsar.client.api.schema.GenericRecord)

Aggregations

ContainerExecResult (org.apache.pulsar.tests.integration.docker.ContainerExecResult)340 Test (org.testng.annotations.Test)82 BrokerContainer (org.apache.pulsar.tests.integration.containers.BrokerContainer)35 ContainerExecException (org.apache.pulsar.tests.integration.docker.ContainerExecException)32 PulsarClient (org.apache.pulsar.client.api.PulsarClient)30 CommandGenerator (org.apache.pulsar.tests.integration.functions.utils.CommandGenerator)18 Gson (com.google.gson.Gson)15 FunctionStatus (org.apache.pulsar.common.policies.data.FunctionStatus)15 Cleanup (lombok.Cleanup)12 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)12 GenericRecord (org.apache.pulsar.client.api.schema.GenericRecord)12 SourceStatus (org.apache.pulsar.common.policies.data.SourceStatus)12 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)9 FunctionStatsImpl (org.apache.pulsar.common.policies.data.FunctionStatsImpl)9 TenantInfo (org.apache.pulsar.common.policies.data.TenantInfo)9 lombok.val (lombok.val)6 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)6 SinkStatus (org.apache.pulsar.common.policies.data.SinkStatus)6 TopicStats (org.apache.pulsar.common.policies.data.TopicStats)6 Tick (org.apache.pulsar.functions.api.examples.pojo.Tick)6