@Test
 public void testFuseThenTagSink() {
   assumeTrue(isMainRun());
   Topology t = newTopology();
   TStream<String> s1 = t.strings("3");
   TStream<String> s2 = t.strings("3");
   testFuseThenTag(s1.print(), s2.print());
 }
 @Test
 public void testSimpleTagsSink() {
   assumeTrue(isMainRun());
   Topology t = newTopology();
   TStream<String> s = t.strings("3");
   testSimpleTags(s.print());
 }
 @Test
 public void testTagBothThenFuseSinkStream() {
   assumeTrue(isMainRun());
   Topology t = newTopology();
   TStream<String> s1 = t.strings("3");
   TStream<String> s2 = t.strings("3");
   testTagBothThenFuse(s1.print(), s2);
 }
Esempio n. 4
0
  /**
   * Publish some messages to a topic; subscribe to the topic and report received messages.
   *
   * @param contextType string value of a {@code StreamsContext.Type}
   * @throws Exception
   */
  public void publishSubscribe(String contextType) throws Exception {

    Map<String, Object> contextConfig = new HashMap<>();
    initContextConfig(contextConfig);

    Topology top = new Topology("mqttSample");

    // A compile time MQTT topic value.
    Supplier<String> topic = new Value<String>(TOPIC);

    // Create the MQTT connector
    MqttStreams mqtt = new MqttStreams(top, createMqttConfig());

    // Create a stream of messages and for the sample, give the
    // consumer a change to become ready
    TStream<Message> msgs = makeStreamToPublish(top).modify(initialDelayFunc(PUB_DELAY_MSEC));

    // Publish the message stream to the topic
    mqtt.publish(msgs, topic);

    // Subscribe to the topic and report received messages
    TStream<Message> rcvdMsgs = mqtt.subscribe(topic);
    rcvdMsgs.print();

    // Submit the topology, to send and receive the messages.
    Future<?> future =
        StreamsContextFactory.getStreamsContext(contextType).submit(top, contextConfig);

    if (contextType.contains("DISTRIBUTED")) {
      System.out.println(
          "\nSee the job's PE console logs for the topology output.\n"
              + "Use Streams Studio or streamtool.  e.g.,\n"
              + "    # identify the job's \"Print\" PE\n"
              + "    streamtool lspes --jobs "
              + future.get()
              + "\n"
              + "    # print the PE's console log\n"
              + "    streamtool viewlog --print --console --pe <the-peid>"
              + "\n");
      System.out.println(
          "Cancel the job using Streams Studio or streamtool. e.g.,\n"
              + "    streamtool canceljob "
              + future.get()
              + "\n");
    } else if (contextType.contains("STANDALONE")) {
      Thread.sleep(15000);
      future.cancel(true);
    }
  }
  @Test
  public void testFusing() {
    assumeTrue(isMainRun());
    Topology t = newTopology();
    TStream<String> s1 = t.strings("3");
    TStream<String> s2 = t.strings("3");
    TStream<String> snf = t.strings("3");

    assertTrue(s1.isPlaceable());

    assertSame(s1.colocate(s2), s1);

    String id1 = getFusingId(s1);
    String id2 = getFusingId(s2);

    assertNotNull(id1);
    assertFalse(id1.isEmpty());

    assertEquals(id1, id2);

    TStream<String> s3 = t.strings("3");
    TStream<String> s4 = t.strings("3");
    TSink s5 = s4.print();
    assertTrue(s5.isPlaceable());

    assertSame(s3.colocate(s4, s5), s3);
    assertEquals(getFusingId(s3), getFusingId(s4));
    assertEquals(getFusingId(s3), getColocate(s5.operator()));

    assertFalse(getFusingId(s1).equals(getFusingId(s3)));

    assertNull(getFusingId(snf));

    TStream<String> s6 = StringStreams.toString(s4);
    s1.colocate(s6);
    assertEquals(getFusingId(s1), getFusingId(s6));
  }