@Test public void testMultiTopicPublish() throws Exception { Topology top = newTopology("testMultiTopicPublish"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false; rcvd1 = rcvd1.filter(tuple -> tuple.matches(mgen.pattern())); rcvd1.sink(t -> System.out.println("rcvd1: "+t)); rcvd2 = rcvd2.filter(tuple -> tuple.matches(mgen.pattern())); rcvd2.sink(t -> System.out.println("rcvd2: "+t));
@Test(expected=IllegalStateException.class) public void testMultiSubNeg() throws Exception { Topology t = newTopology("testMultiSubNeg"); MsgGenerator mgen = new MsgGenerator(t.getName()); String topic1 = getKafkaTopics()[0]; String topic2 = getKafkaTopics()[1];
@Test public void testConnectRetryPub() throws Exception { Topology top = newTopology("testConnectRetryPub"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false;
@Test public void testWithKey() throws Exception { Topology t = newTopology("testWithKey"); MsgGenerator mgen = new MsgGenerator(t.getName()); String topic = getKafkaTopics()[0]; String groupId = newGroupId(t.getName());
MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false;
@Test public void testPubSubBytes() throws Exception { Topology t = newTopology("testPubSubBytes"); MsgGenerator mgen = new MsgGenerator(t.getName()); String topic = getKafkaTopics()[0]; String groupId = newGroupId(t.getName());
@Test public void testSubscribeFnThrow() throws Exception { Topology top = newTopology("testSubscribeFnThrow"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false;
@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 testIdleSubscribe() throws Exception { Topology top = newTopology("testIdleSubscribe"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean retain = false;
@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 testMultiPub() throws Exception { Topology t = newTopology("testMultiPub"); MsgGenerator mgen = new MsgGenerator(t.getName()); String topic1 = getKafkaTopics()[0]; String topic2 = getKafkaTopics()[1];
@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 testRetainedTrue() throws Exception { Topology top = newTopology("testRetainedTrue"); MsgGenerator mgen = new MsgGenerator(top.getName()); int qos = 0; boolean isRetained = true;
@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 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 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 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])); }