@Test public void testSimple() throws Exception { Topology t = newTopology("testSimple"); Map<String, Object> configMap = initRabbitmqConfig(); MsgGenerator generator = new MsgGenerator(t.getName()); String queue = "testQueue"; List<String> msgs = createMsgs(generator, queue, getMsg1(), getMsg2()); TStream<String> stream = PlumbingStreams.blockingOneShotDelay( t.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); RabbitmqConsumer consumer = new RabbitmqConsumer(t, () -> configMap); TStream<String> receivedStream = consumer.subscribe((byte[] bytes) -> new String(bytes), queue); RabbitmqProducer producer = new RabbitmqProducer(t, () -> configMap); TSink<String> sink = producer.publish(stream, queue, (String s) -> s.getBytes()); completeAndValidate("", t, receivedStream, generator, SEC_TIMEOUT, msgs.toArray(new String[0])); assertNotNull(sink); }
@Test public void testPublishFnThrow() throws Exception { Topology top = newTopology("testPublishFnThrow"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false;
@Test public void testRetainedTrue() throws Exception { Topology top = newTopology("testRetainedTrue"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean isRetained = true;
@Test public void testIdleSubscribe() throws Exception { Topology top = newTopology("testIdleSubscribe"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false;
@Test public void testMultiPub() throws Exception { Topology t = newTopology("testMultiPub"); MsgGenerator mgen = new MsgGenerator(t.getName()); String topic1 = getKafkaTopics()[0]; String topic2 = getKafkaTopics()[1];
@Test public void testRetainedFalse() throws Exception { Topology top = newTopology("testRetainedFalse"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean isRetained = false;
@Test public void testGenericPublish() throws Exception { Topology top = newTopology("testGenericPublish"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false;
@Test public void testIdlePublish() throws Exception { Topology top = newTopology("testIdlePublish"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; String pubClientId = newClientId(top.getName()+"_pub"); String subClientId = newClientId(top.getName()+"_sub"); String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); // Exercise idle timeouts. We won't have any direct // evidence that an idle disconnect/reconnect happen // but the code coverage will verify the paths were // exercised TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); s = PlumbingStreams.blockingThrottle( top.collection(msgs), 4, TimeUnit.SECONDS); MqttConfig pubConfig = newConfig(getServerURI(), pubClientId); pubConfig.setIdleTimeout(2); MqttStreams pubMqtt = new MqttStreams(top, () -> pubConfig); MqttConfig subConfig = newConfig(getServerURI(), subClientId); MqttStreams subMqtt = new MqttStreams(top, () -> subConfig); pubMqtt.publish(s, topic, qos, retain); TStream<String> rcvd = subMqtt.subscribe(topic, qos); completeAndValidate(subClientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); }
@Test public void testMultiTopicSubscribe() throws Exception { Topology top = newTopology("testMultiTopicSubscribe"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; String clientId = newClientId(top.getName()); String topic1 = getMqttTopics()[0] + "/1"; String topic2 = getMqttTopics()[0] + "/2"; String topics = getMqttTopics()[0] + "/+"; List<String> msgs1 = createMsgs(mgen, topic1, getMsg1(), getMsg2()); List<String> msgs2 = createMsgs(mgen, topic2, getMsg1(), getMsg2()); List<String> msgs = new ArrayList<>(); msgs.addAll(msgs1); msgs.addAll(msgs2); TStream<String> s1 = PlumbingStreams.blockingOneShotDelay( top.collection(msgs1), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); TStream<String> s2 = PlumbingStreams.blockingOneShotDelay( top.collection(msgs2), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // Test multi-topic subscribe MqttConfig config = newConfig(getServerURI(), clientId); MqttStreams mqtt = new MqttStreams(top, () -> config); mqtt.publish(s1, topic1, qos, retain); mqtt.publish(s2, topic2, qos, retain); TStream<String> rcvd = mqtt.subscribe(topics, qos); completeAndValidate(false/*ordered*/, clientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); }
@Test public void testConnectFail() throws Exception { Topology top = newTopology("testConnectFail"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false;
@Test public void testQoS2() throws Exception { Topology top = newTopology("testQoS2"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 2; boolean retain = false; String clientId = newClientId(top.getName()); String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // TODO something to verify that we actually provide // the QoS semantics. // Also improve code coverage with persistence override // Test publish(TStream<String>, topic, qos) // Test TStream<String> subscribe(topic, qos) MqttConfig config = newConfig(getServerURI(), clientId); config.setPersistence(new MemoryPersistence()); MqttStreams mqtt = new MqttStreams(top, () -> config); mqtt.publish(s, topic, qos, retain); TStream<String> rcvd = mqtt.subscribe(topic, qos); completeAndValidate(clientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); }
@Test public void testSslClientAuth() throws Exception { Topology top = newTopology("testSslClientAuth"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; String clientId = newClientId(top.getName()); String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // Test publish(TStream<String>, topic, qos) // Test TStream<String> subscribe(topic, qos) // System.setProperty("javax.net.debug", "ssl"); // or "all"; "help" for full list setSslAuthInfo("sslClientAuth"); MqttConfig config = newConfig(getSslClientAuthServerURI(), clientId); MqttStreams mqtt = new MqttStreams(top, () -> config); TSink<String> sink = mqtt.publish(s, topic, qos, retain); TStream<String> rcvd = mqtt.subscribe(topic, qos); completeAndValidate(clientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); assertNotNull(sink); }
@Test public void testSsl() throws Exception { Topology top = newTopology("testSsl"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; String clientId = newClientId(top.getName()); String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // Test publish(TStream<String>, topic, qos) // Test TStream<String> subscribe(topic, qos) // System.setProperty("javax.net.debug", "ssl"); // or "all"; "help" for full list setSslAuthInfo("ssl"); MqttConfig config = newConfig(getSslServerURI(), clientId); MqttStreams mqtt = new MqttStreams(top, () -> config); TSink<String> sink = mqtt.publish(s, topic, qos, retain); TStream<String> rcvd = mqtt.subscribe(topic, qos); completeAndValidate(clientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); assertNotNull(sink); }
@Test public void testMultiConnector() throws Exception { Topology top = newTopology("testMultiConnector"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; String pubClientId = newClientId(top.getName())+"_pub"; String subClientId = newClientId(top.getName())+"_sub"; String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // Test separate connectors for pub and sub MqttConfig config = newConfig(getServerURI(), pubClientId); MqttStreams mqttPub = new MqttStreams(top, () -> config); mqttPub.publish(s, topic, qos, retain); MqttConfig configSub = newConfig(getServerURI(), subClientId); MqttStreams mqttSub = new MqttStreams(top, () -> configSub); TStream<String> rcvd = mqttSub.subscribe(topic, qos); completeAndValidate(pubClientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); }
@Test public void testQoS1() throws Exception { Topology top = newTopology("testQoS1"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 1; boolean retain = false; String clientId = newClientId(top.getName()); String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // TODO something to verify that we actually provide // the QoS semantics. // Test publish(TStream<String>, topic, qos) // Test TStream<String> subscribe(topic, qos) MqttConfig config = newConfig(getServerURI(), clientId); MqttStreams mqtt = new MqttStreams(top, () -> config); mqtt.publish(s, topic, qos, retain); TStream<String> rcvd = mqtt.subscribe(topic, qos); completeAndValidate(clientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); }
@Test public void testActionTime() throws Exception { Topology top = newTopology("testActionTime"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; String clientId = newClientId(top.getName()); String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // Test publish(TStream<String>, topic, qos) // Test TStream<String> subscribe(topic, qos) MqttConfig config = newConfig(getServerURI(), clientId); config.setActionTimeToWaitMillis(3*1000); MqttStreams mqtt = new MqttStreams(top, () -> config); mqtt.publish(s, topic, qos, retain); TStream<String> rcvd = mqtt.subscribe(topic, qos); completeAndValidate(clientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); }
@Test public void testStringPublish() throws Exception { Topology top = newTopology("testStringPublish"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; String clientId = newClientId(top.getName()); String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // Test publish(TStream<String>, topic, qos) // Test TStream<String> subscribe(topic, qos) MqttConfig config = newConfig(getServerURI(), clientId); MqttStreams mqtt = new MqttStreams(top, () -> config); TSink<String> sink = mqtt.publish(s, topic, qos, retain); TStream<String> rcvd = mqtt.subscribe(topic, qos); completeAndValidate(clientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); assertNotNull(sink); }
@Test public void testMultipleServerURL() throws Exception { Topology top = newTopology("testMultipleServerURL"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; String clientId = newClientId(top.getName()); String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // Test server URL selection - supply a bogus 1st URL. String[] serverURLs = new String[] {"tcp://localhost:31999", getServerURI()}; MqttConfig config = newConfig(serverURLs[0], clientId); config.setServerURLs(serverURLs); MqttStreams mqtt = new MqttStreams(top, () -> config); mqtt.publish(s, topic, qos, retain); TStream<String> rcvd = mqtt.subscribe(topic, qos); completeAndValidate(clientId, top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); }
@Test public void testSimple() throws Exception { Topology t = newTopology("testSimple"); MsgGenerator mgen = new MsgGenerator(t.getName()); String topic = getKafkaTopics()[0]; String groupId = newGroupId(t.getName()); List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( t.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); Map<String,Object> pConfig = newProducerConfig(); KafkaProducer producer = new KafkaProducer(t, () -> pConfig); TSink<String> sink = producer.publish(s, topic); Map<String,Object> cConfig = newConsumerConfig(groupId); KafkaConsumer consumer = new KafkaConsumer(t, () -> cConfig); TStream<String> rcvd = consumer.subscribe( rec -> rec.value(), topic); completeAndValidate("", t, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); assertNotNull(sink); }
@Test public void testAutoClientId() throws Exception { Topology top = newTopology("testAutoClientId"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; String topic = getMqttTopics()[0]; List<String> msgs = createMsgs(mgen, topic, getMsg1(), getMsg2()); TStream<String> s = PlumbingStreams.blockingOneShotDelay( top.collection(msgs), PUB_DELAY_MSEC, TimeUnit.MILLISECONDS); // Test with auto-generated clientId MqttConfig config = newConfig(getServerURI(), null/*clientId*/); MqttStreams mqtt = new MqttStreams(top, () -> config); mqtt.publish(s, topic, qos, retain); TStream<String> rcvd = mqtt.subscribe(topic, qos); completeAndValidate("some-auto-clientId", top, rcvd, mgen, SEC_TIMEOUT, msgs.toArray(new String[0])); }