@Override public void deleteTopic(String topic) throws TopicNotFoundException, IOException { messagingService.deleteTopic(namespace.topic(topic)); } }
@Override public void deleteTopic(String topic) throws TopicNotFoundException, IOException { messagingService.deleteTopic(namespace.topic(topic)); } }
@Override public void deleteTopic(TopicId topicId) throws TopicNotFoundException, IOException { getMessagingService().deleteTopic(topicId); }
@Override public void deleteTopic(TopicId topicId) throws TopicNotFoundException, IOException { getMessagingService().deleteTopic(topicId); }
@DELETE @Path("/topics/{topic}") public void deleteTopic(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception { TopicId topicId = new NamespaceId(namespace).topic(topic); messagingService.deleteTopic(topicId); responder.sendStatus(HttpResponseStatus.OK); }
@DELETE @Path("/topics/{topic}") public void deleteTopic(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception { TopicId topicId = new NamespaceId(namespace).topic(topic); messagingService.deleteTopic(topicId); responder.sendStatus(HttpResponseStatus.OK); }
@Test public void testDeletes() throws Exception { TopicId topicId = new NamespaceId("ns1").topic("del"); TopicMetadata metadata = new TopicMetadata(topicId, "ttl", "100"); for (int j = 0; j < 10; j++) { client.createTopic(metadata); String m1 = String.format("m%d", j); String m2 = String.format("m%d", j + 1); Assert.assertNull(client.publish(StoreRequestBuilder.of(topicId).addPayload(m1).addPayload(m2).build())); // Fetch messages non-transactionally List<RawMessage> messages = new ArrayList<>(); try (CloseableIterator<RawMessage> iterator = client.prepareFetch(topicId).fetch()) { Iterators.addAll(messages, iterator); } Assert.assertEquals(2, messages.size()); Set<String> receivedMessages = new HashSet<>(); for (RawMessage message : messages) { receivedMessages.add(Bytes.toString(message.getPayload())); } Assert.assertTrue(receivedMessages.contains(m1)); Assert.assertTrue(receivedMessages.contains(m2)); client.deleteTopic(topicId); } }
messagingService.deleteTopic(topicId);
@Test public void testChunkConsume() throws Exception { // This test is to verify the message fetching body producer works correctly TopicId topicId = new NamespaceId("ns1").topic("testChunkConsume"); client.createTopic(new TopicMetadata(topicId)); // Publish 10 messages, each payload is half the size of the chunk size int payloadSize = cConf.getInt(Constants.MessagingSystem.HTTP_SERVER_CONSUME_CHUNK_SIZE) / 2; for (int i = 0; i < 10; i++) { String payload = Strings.repeat(Integer.toString(i), payloadSize); client.publish(StoreRequestBuilder.of(topicId).addPayload(payload).build()); } // Fetch messages. All of them should be fetched correctly List<RawMessage> messages = new ArrayList<>(); try (CloseableIterator<RawMessage> iterator = client.prepareFetch(topicId).fetch()) { Iterators.addAll(messages, iterator); } Assert.assertEquals(10, messages.size()); for (int i = 0; i < 10; i++) { RawMessage message = messages.get(i); Assert.assertEquals(payloadSize, message.getPayload().length); String payload = Strings.repeat(Integer.toString(i), payloadSize); Assert.assertEquals(payload, Bytes.toString(message.getPayload())); } client.deleteTopic(topicId); }
messagingService.deleteTopic(topicId);
@Test public void testGeMetadata() throws Exception { TopicId topicId = new NamespaceId("ns2").topic("d"); TopicMetadata metadata = new TopicMetadata(topicId, "ttl", "100"); for (int i = 1; i <= 5; i++) { client.createTopic(metadata); TopicMetadata topicMetadata = client.getTopic(topicId); Assert.assertEquals(100, topicMetadata.getTTL()); Assert.assertEquals(i, topicMetadata.getGeneration()); client.deleteTopic(topicId); } }
@Test public void testTxMaxLifeTime() throws Exception { NamespaceId nsId = new NamespaceId("txCheck"); TopicId topic1 = nsId.topic("t1"); // Create a topic client.createTopic(new TopicMetadata(topic1)); final RollbackDetail rollbackDetail = client.publish(StoreRequestBuilder.of(topic1).setTransaction(1L) .addPayload("a").addPayload("b").build()); try { client.publish(StoreRequestBuilder.of(topic1) .setTransaction(-Long.MAX_VALUE).addPayload("c").addPayload("d").build()); Assert.fail("Expected IOException"); } catch (IOException ex) { // expected } Set<String> msgs = new HashSet<>(); CloseableIterator<RawMessage> messages = client.prepareFetch(topic1).fetch(); while (messages.hasNext()) { RawMessage message = messages.next(); msgs.add(Bytes.toString(message.getPayload())); } Assert.assertEquals(2, msgs.size()); Assert.assertTrue(msgs.contains("a")); Assert.assertTrue(msgs.contains("b")); messages.close(); client.rollback(topic1, rollbackDetail); client.deleteTopic(topic1); }
Assert.assertEquals(Integer.toString(10), payload1); client.deleteTopic(topicId);
client.deleteTopic(topic1); client.deleteTopic(topic2); client.deleteTopic(topic1); Assert.fail("Expect TopicNotFoundException"); } catch (TopicNotFoundException e) {
client.deleteTopic(topicId);