Search in sources :

Example 1 with TestPerson

use of com.hazelcast.jet.impl.connector.ReadFilesPTest.TestPerson in project hazelcast by hazelcast.

the class WriteFilePTest method test_JsonFile.

@Test
public void test_JsonFile() throws IOException {
    // Given
    Pipeline p = Pipeline.create();
    TestPerson testPerson = new TestPerson("foo", 5, true);
    p.readFrom(TestSources.items(testPerson)).writeTo(Sinks.json(directory.toString()));
    // When
    instance().getJet().newJob(p).join();
    // Then
    List<String> lines = Files.list(directory).flatMap(file -> uncheckCall(() -> Files.readAllLines(file).stream())).collect(Collectors.toList());
    assertEquals(1, lines.size());
    TestPerson actual = JSON.std.beanFrom(TestPerson.class, lines.get(0));
    assertEquals(testPerson, actual);
}
Also used : AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) LongSupplier(java.util.function.LongSupplier) QuickTest(com.hazelcast.test.annotation.QuickTest) Processors.mapP(com.hazelcast.jet.core.processor.Processors.mapP) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Collections.singletonList(java.util.Collections.singletonList) After(org.junit.After) Map(java.util.Map) DAG(com.hazelcast.jet.core.DAG) Path(java.nio.file.Path) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) Serializable(java.io.Serializable) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) TestSupport(com.hazelcast.jet.core.test.TestSupport) DISABLE_ROLLING(com.hazelcast.jet.pipeline.FileSinkBuilder.DISABLE_ROLLING) Util.uncheckCall(com.hazelcast.jet.impl.util.Util.uncheckCall) TEMP_FILE_SUFFIX(com.hazelcast.jet.pipeline.FileSinkBuilder.TEMP_FILE_SUFFIX) IntStream(java.util.stream.IntStream) BeforeClass(org.junit.BeforeClass) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) JobProxy(com.hazelcast.jet.impl.JobProxy) Function(java.util.function.Function) Charset(java.nio.charset.Charset) TestPerson(com.hazelcast.jet.impl.connector.ReadFilesPTest.TestPerson) NoSuchElementException(java.util.NoSuchElementException) Nonnull(javax.annotation.Nonnull) Job(com.hazelcast.jet.Job) Before(org.junit.Before) TestInbox(com.hazelcast.jet.core.test.TestInbox) JobRepository(com.hazelcast.jet.impl.JobRepository) IOUtil(com.hazelcast.internal.nio.IOUtil) Iterator(java.util.Iterator) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) Semaphore(java.util.concurrent.Semaphore) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) Vertex(com.hazelcast.jet.core.Vertex) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestSources(com.hazelcast.jet.pipeline.test.TestSources) SinkProcessors.writeFileP(com.hazelcast.jet.core.processor.SinkProcessors.writeFileP) JSON(com.fasterxml.jackson.jr.ob.JSON) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) HOURS(java.util.concurrent.TimeUnit.HOURS) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Comparator(java.util.Comparator) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) TestPerson(com.hazelcast.jet.impl.connector.ReadFilesPTest.TestPerson) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

JSON (com.fasterxml.jackson.jr.ob.JSON)1 IOUtil (com.hazelcast.internal.nio.IOUtil)1 Job (com.hazelcast.jet.Job)1 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)1 JobConfig (com.hazelcast.jet.config.JobConfig)1 EXACTLY_ONCE (com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE)1 AbstractProcessor (com.hazelcast.jet.core.AbstractProcessor)1 DAG (com.hazelcast.jet.core.DAG)1 Edge.between (com.hazelcast.jet.core.Edge.between)1 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)1 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)1 Vertex (com.hazelcast.jet.core.Vertex)1 Processors.mapP (com.hazelcast.jet.core.processor.Processors.mapP)1 SinkProcessors.writeFileP (com.hazelcast.jet.core.processor.SinkProcessors.writeFileP)1 TestInbox (com.hazelcast.jet.core.test.TestInbox)1 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)1 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)1 TestSupport (com.hazelcast.jet.core.test.TestSupport)1 Tuple2.tuple2 (com.hazelcast.jet.datamodel.Tuple2.tuple2)1 JobProxy (com.hazelcast.jet.impl.JobProxy)1