Search in sources :

Example 1 with Person

use of com.hazelcast.jet.protobuf.Messages.Person in project hazelcast by hazelcast.

the class JobSerializerTest method when_serializerIsNotRegistered_then_throwsException.

@Test
public void when_serializerIsNotRegistered_then_throwsException() {
    String listName = "list-1";
    List<Person> list = client().getList(listName);
    list.add(Person.newBuilder().setName("Joe").setAge(33).build());
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(Sources.<Person>list(listName)).map(Person::getName).writeTo(Sinks.logger());
    assertThatThrownBy(() -> client().getJet().newJob(pipeline, new JobConfig()).join()).hasCauseInstanceOf(JetException.class);
}
Also used : Person(com.hazelcast.jet.protobuf.Messages.Person) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with Person

use of com.hazelcast.jet.protobuf.Messages.Person in project hazelcast by hazelcast.

the class JobSerializerTest method when_serializerIsRegisteredForDistributedJob_then_itIsAvailableForAllStages.

@Test
public void when_serializerIsRegisteredForDistributedJob_then_itIsAvailableForAllStages() {
    List<String> input = IntStream.range(0, 10_000).boxed().map(t -> Integer.toString(t)).collect(toList());
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(TestSources.items(input)).map(name -> Person.newBuilder().setName(name).build()).groupingKey(identity()).filterUsingService(sharedService(ctx -> null), (s, k, v) -> true).map(person -> person.getName()).writeTo(AssertionSinks.assertAnyOrder(input));
    client().getJet().newJob(pipeline, new JobConfig().registerSerializer(Person.class, PersonSerializer.class)).join();
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) IntStream(java.util.stream.IntStream) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BeforeClass(org.junit.BeforeClass) ServiceFactories.sharedService(com.hazelcast.jet.pipeline.ServiceFactories.sharedService) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collections.singletonList(java.util.Collections.singletonList) JetException(com.hazelcast.jet.JetException) ClientListProxy(com.hazelcast.client.impl.proxy.ClientListProxy) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ClientConfig(com.hazelcast.client.config.ClientConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) Animal(com.hazelcast.jet.protobuf.Messages.Animal) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) Config(com.hazelcast.config.Config) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) Person(com.hazelcast.jet.protobuf.Messages.Person) Category(org.junit.experimental.categories.Category) Sources(com.hazelcast.jet.pipeline.Sources) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FunctionEx.identity(com.hazelcast.function.FunctionEx.identity) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with Person

use of com.hazelcast.jet.protobuf.Messages.Person in project hazelcast by hazelcast.

the class ProtobufSerializerTest method when_serializes_then_isAbleToDeserialize.

@Test
public void when_serializes_then_isAbleToDeserialize() {
    // Given
    Person original = Person.newBuilder().setName("Joe").setAge(18).build();
    StreamSerializer<Person> serializer = ProtobufSerializer.from(Person.class, 1);
    // When
    Person transformed = deserialize(serializer, serialize(serializer, original));
    // Then
    assertThat(transformed).isEqualTo(original);
}
Also used : Person(com.hazelcast.jet.protobuf.Messages.Person) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with Person

use of com.hazelcast.jet.protobuf.Messages.Person in project hazelcast by hazelcast.

the class JobSerializerTest method when_serializerIsRegistered_then_itIsAvailableForTheJob.

@Test
public void when_serializerIsRegistered_then_itIsAvailableForTheJob() {
    String listName = "list-2";
    List<Person> list = client().getList(listName);
    list.add(Person.newBuilder().setName("Joe").setAge(33).build());
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(Sources.<Person>list(listName)).map(Person::getName).writeTo(AssertionSinks.assertAnyOrder(singletonList("Joe")));
    client().getJet().newJob(pipeline, new JobConfig().registerSerializer(Person.class, PersonSerializer.class)).join();
}
Also used : Person(com.hazelcast.jet.protobuf.Messages.Person) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Person (com.hazelcast.jet.protobuf.Messages.Person)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 JobConfig (com.hazelcast.jet.config.JobConfig)3 Pipeline (com.hazelcast.jet.pipeline.Pipeline)3 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientListProxy (com.hazelcast.client.impl.proxy.ClientListProxy)1 Config (com.hazelcast.config.Config)1 SerializerConfig (com.hazelcast.config.SerializerConfig)1 FunctionEx.identity (com.hazelcast.function.FunctionEx.identity)1 JetException (com.hazelcast.jet.JetException)1 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)1 ServiceFactories.sharedService (com.hazelcast.jet.pipeline.ServiceFactories.sharedService)1 Sinks (com.hazelcast.jet.pipeline.Sinks)1 Sources (com.hazelcast.jet.pipeline.Sources)1 AssertionSinks (com.hazelcast.jet.pipeline.test.AssertionSinks)1 TestSources (com.hazelcast.jet.pipeline.test.TestSources)1 Animal (com.hazelcast.jet.protobuf.Messages.Animal)1 Collections.singletonList (java.util.Collections.singletonList)1