examples/dataflow-streaming-benchmark/src/test/java/com/google/cloud/pso/pipeline/StreamingBenchmarkTest.java
/** Tests the {@link MessageGeneratorFn} generates fake data. */
Tests the  MessageGeneratorFn generates fake data.
Tests the MessageGeneratorFn generates fake data .
@Test
  public void testMessageGenerator() throws IOException {
    String schema =
        "{"
            + "\"id\": \"{{uuid()}}\", "
            + "\"eventTime\": \"{{timestamp()}}\", "
            + "\"username\": \"{{username()}}\", "
            + "\"score\": {{integer(0,100)}}"
            + "}";
    File file = tempFolder.newFile();
    writeToFile(file.getAbsolutePath(), Lists.newArrayList(schema));
     Act
    PCollection<PubsubMessage> results =
        pipeline
            .apply("CreateInput", Create.of(0L))
            .apply("GenerateMessage", ParDo.of(new MessageGeneratorFn(file.getAbsolutePath())));
     Assert
    PAssert.that(results)
        .satisfies(
            input -> {
              PubsubMessage message = input.iterator().next();
              assertThat(message, is(notNullValue()));
              assertThat(message.getPayload(), is(notNullValue()));
              assertThat(message.getAttributeMap(), is(notNullValue()));
              return null;
            });
    pipeline.run();
  }
@ Test public void testMessageGenerator ( ) throws IOException { String schema = "{" + "\"id\": \"{{uuid()}}\", " + "\"eventTime\": \"{{timestamp()}}\", " + "\"username\": \"{{username()}}\", " + "\"score\": {{integer(0,100)}}" + "}" ; File file = tempFolder . newFile ( ) ; writeToFile ( file . getAbsolutePath ( ) , Lists . newArrayList ( schema ) ) ; PCollection < PubsubMessage > results = pipeline . apply ( "CreateInput" , Create . of ( 0L ) ) . apply ( "GenerateMessage" , ParDo . of ( new MessageGeneratorFn ( file . getAbsolutePath ( ) ) ) ) ; PAssert . that ( results ) . satisfies ( input -> { PubsubMessage message = input . iterator ( ) . next ( ) ; assertThat ( message , is ( notNullValue ( ) ) ) ; assertThat ( message . getPayload ( ) , is ( notNullValue ( ) ) ) ; assertThat ( message . getAttributeMap ( ) , is ( notNullValue ( ) ) ) ; return null ; } ) ; pipeline . run ( ) ; }
Tests the {@link MessageGeneratorFn} generates fake data.
Tests the { @link MessageGeneratorFn } generates fake data .
// Arrange // // Act // // Assert //