use of org.apache.pulsar.client.impl.TypedMessageBuilderImpl in project pulsar by yahoo.
the class V1_ProducerConsumerTest method testInvalidSequence.
@Test
public void testInvalidSequence() throws Exception {
log.info("-- Starting {} test --", methodName);
PulsarClient client1 = PulsarClient.builder().serviceUrl(pulsar.getWebServiceAddress()).build();
client1.close();
try {
client1.newConsumer().topic("persistent://my-property/use/my-ns/my-topic6").subscriptionName("my-subscriber-name").subscriptionType(SubscriptionType.Exclusive).subscribe();
Assert.fail("Should fail");
} catch (PulsarClientException e) {
Assert.assertTrue(e instanceof PulsarClientException.AlreadyClosedException);
}
try {
client1.newProducer().topic("persistent://my-property/use/my-ns/my-topic6").create();
Assert.fail("Should fail");
} catch (PulsarClientException e) {
Assert.assertTrue(e instanceof PulsarClientException.AlreadyClosedException);
}
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic("persistent://my-property/use/my-ns/my-topic6").subscriptionName("my-subscriber-name").subscriptionType(SubscriptionType.Exclusive).subscribe();
Producer<byte[]> producer = pulsarClient.newProducer().topic("persistent://my-property/use/my-ns/my-topic6").create();
try {
TypedMessageBuilder<byte[]> builder = producer.newMessage().value("InvalidMessage".getBytes());
Message<byte[]> msg = ((TypedMessageBuilderImpl<byte[]>) builder).getMessage();
consumer.acknowledge(msg);
} catch (PulsarClientException.InvalidMessageException e) {
// ok
}
consumer.close();
try {
consumer.receive();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
try {
consumer.unsubscribe();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
producer.close();
try {
producer.send("message".getBytes());
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
}
use of org.apache.pulsar.client.impl.TypedMessageBuilderImpl in project pulsar by yahoo.
the class PartitionedProducerConsumerTest method testInvalidSequence.
@Test(timeOut = 30000)
public void testInvalidSequence() throws Exception {
log.info("-- Starting {} test --", methodName);
int numPartitions = 4;
TopicName topicName = TopicName.get("persistent://my-property/my-ns/my-partitionedtopic4-" + System.currentTimeMillis());
admin.topics().createPartitionedTopic(topicName.toString(), numPartitions);
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName.toString()).subscriptionName("my-subscriber-name").subscribe();
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName.toString()).enableBatching(false).messageRoutingMode(MessageRoutingMode.SinglePartition).create();
try {
TypedMessageBuilderImpl<byte[]> mb = (TypedMessageBuilderImpl<byte[]>) producer.newMessage().value("InvalidMessage".getBytes());
consumer.acknowledge(mb.getMessage());
} catch (PulsarClientException.InvalidMessageException e) {
// ok
}
consumer.close();
try {
consumer.receive();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
try {
consumer.unsubscribe();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
producer.close();
try {
producer.send("message".getBytes());
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
admin.topics().deletePartitionedTopic(topicName.toString());
}
use of org.apache.pulsar.client.impl.TypedMessageBuilderImpl in project incubator-pulsar by apache.
the class ContextImplTest method setup.
@BeforeMethod(alwaysRun = true)
public void setup() throws PulsarClientException {
config = new InstanceConfig();
config.setExposePulsarAdminClientEnabled(true);
FunctionDetails functionDetails = FunctionDetails.newBuilder().setUserConfig("").build();
config.setFunctionDetails(functionDetails);
logger = mock(Logger.class);
pulsarAdmin = mock(PulsarAdmin.class);
producer = mock(Producer.class);
client = mock(PulsarClientImpl.class);
when(client.newProducer()).thenReturn(new ProducerBuilderImpl(client, Schema.BYTES));
when(client.createProducerAsync(any(ProducerConfigurationData.class), any(), any())).thenReturn(CompletableFuture.completedFuture(producer));
when(client.getSchema(anyString())).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
when(producer.sendAsync(anyString())).thenReturn(CompletableFuture.completedFuture(null));
clientBuilder = mock(ClientBuilder.class);
when(clientBuilder.build()).thenReturn(client);
TypedMessageBuilder messageBuilder = spy(new TypedMessageBuilderImpl(mock(ProducerBase.class), Schema.STRING));
doReturn(new CompletableFuture<>()).when(messageBuilder).sendAsync();
when(producer.newMessage()).thenReturn(messageBuilder);
context = new ContextImpl(config, logger, client, new EnvironmentBasedSecretsProvider(), FunctionCollectorRegistry.getDefaultImplementation(), new String[0], FunctionDetails.ComponentType.FUNCTION, null, new InstanceStateManager(), pulsarAdmin, clientBuilder);
context.setCurrentMessageContext((Record<String>) () -> null);
}
use of org.apache.pulsar.client.impl.TypedMessageBuilderImpl in project incubator-pulsar by apache.
the class PartitionedProducerConsumerTest method testInvalidSequence.
@Test(timeOut = 30000)
public void testInvalidSequence() throws Exception {
log.info("-- Starting {} test --", methodName);
int numPartitions = 4;
TopicName topicName = TopicName.get("persistent://my-property/my-ns/my-partitionedtopic4-" + System.currentTimeMillis());
admin.topics().createPartitionedTopic(topicName.toString(), numPartitions);
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName.toString()).subscriptionName("my-subscriber-name").subscribe();
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName.toString()).enableBatching(false).messageRoutingMode(MessageRoutingMode.SinglePartition).create();
try {
TypedMessageBuilderImpl<byte[]> mb = (TypedMessageBuilderImpl<byte[]>) producer.newMessage().value("InvalidMessage".getBytes());
consumer.acknowledge(mb.getMessage());
} catch (PulsarClientException.InvalidMessageException e) {
// ok
}
consumer.close();
try {
consumer.receive();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
try {
consumer.unsubscribe();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
producer.close();
try {
producer.send("message".getBytes());
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
admin.topics().deletePartitionedTopic(topicName.toString());
}
use of org.apache.pulsar.client.impl.TypedMessageBuilderImpl in project incubator-pulsar by apache.
the class V1_ProducerConsumerTest method testInvalidSequence.
@Test
public void testInvalidSequence() throws Exception {
log.info("-- Starting {} test --", methodName);
PulsarClient client1 = PulsarClient.builder().serviceUrl(pulsar.getWebServiceAddress()).build();
client1.close();
try {
client1.newConsumer().topic("persistent://my-property/use/my-ns/my-topic6").subscriptionName("my-subscriber-name").subscriptionType(SubscriptionType.Exclusive).subscribe();
Assert.fail("Should fail");
} catch (PulsarClientException e) {
Assert.assertTrue(e instanceof PulsarClientException.AlreadyClosedException);
}
try {
client1.newProducer().topic("persistent://my-property/use/my-ns/my-topic6").create();
Assert.fail("Should fail");
} catch (PulsarClientException e) {
Assert.assertTrue(e instanceof PulsarClientException.AlreadyClosedException);
}
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic("persistent://my-property/use/my-ns/my-topic6").subscriptionName("my-subscriber-name").subscriptionType(SubscriptionType.Exclusive).subscribe();
Producer<byte[]> producer = pulsarClient.newProducer().topic("persistent://my-property/use/my-ns/my-topic6").create();
try {
TypedMessageBuilder<byte[]> builder = producer.newMessage().value("InvalidMessage".getBytes());
Message<byte[]> msg = ((TypedMessageBuilderImpl<byte[]>) builder).getMessage();
consumer.acknowledge(msg);
} catch (PulsarClientException.InvalidMessageException e) {
// ok
}
consumer.close();
try {
consumer.receive();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
try {
consumer.unsubscribe();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
producer.close();
try {
producer.send("message".getBytes());
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
}
Aggregations