This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit f6e753fb3f64bddbc505693c842bf04215aa145b Author: Matthieu Baechler <[email protected]> AuthorDate: Thu Oct 17 16:06:48 2019 +0200 JAMES-2813 make sure only constants are static and follow usual naming convention --- .../distributed/DistributedTaskManagerTest.java | 65 +++++++++++----------- .../distributed/TaskEventsSerializationTest.java | 47 ++++++++-------- 2 files changed, 57 insertions(+), 55 deletions(-) diff --git a/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java b/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java index 2b60b6e..73170a5 100644 --- a/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java +++ b/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/DistributedTaskManagerTest.java @@ -73,7 +73,8 @@ import org.junit.jupiter.api.extension.RegisterExtension; import com.github.steveash.guavate.Guavate; class DistributedTaskManagerTest implements TaskManagerContract { - private static class TrackedRabbitMQWorkQueueSupplier implements WorkQueueSupplier { + + static class TrackedRabbitMQWorkQueueSupplier implements WorkQueueSupplier { private final List<RabbitMQWorkQueue> workQueues; private final RabbitMQWorkQueueSupplier supplier; @@ -96,51 +97,51 @@ class DistributedTaskManagerTest implements TaskManagerContract { } } - private static final JsonTaskSerializer TASK_SERIALIZER = new JsonTaskSerializer( - TestTaskDTOModules.COMPLETED_TASK_MODULE, - TestTaskDTOModules.FAILED_TASK_MODULE, - TestTaskDTOModules.THROWING_TASK_MODULE, - TestTaskDTOModules.MEMORY_REFERENCE_TASK_MODULE.apply(new MemoryReferenceTaskStore()), - TestTaskDTOModules.MEMORY_REFERENCE_WITH_COUNTER_TASK_MODULE.apply(new MemoryReferenceWithCounterTaskStore()) - ); - - private static final JsonTaskAdditionalInformationSerializer JSON_TASK_ADDITIONAL_INFORMATION_SERIALIZER = new JsonTaskAdditionalInformationSerializer(MemoryReferenceWithCounterTaskAdditionalInformationDTO.SERIALIZATION_MODULE); - - private static final Hostname HOSTNAME = new Hostname("foo"); - private static final Hostname HOSTNAME_2 = new Hostname("bar"); - private static final Set<EventDTOModule<?, ?>> MODULES = TasksSerializationModule.list(TASK_SERIALIZER, JSON_TASK_ADDITIONAL_INFORMATION_SERIALIZER).stream().collect(Guavate.toImmutableSet()); - private static final JsonEventSerializer EVENT_SERIALIZER = new JsonEventSerializer(MODULES); + static final JsonTaskAdditionalInformationSerializer JSON_TASK_ADDITIONAL_INFORMATION_SERIALIZER = new JsonTaskAdditionalInformationSerializer(MemoryReferenceWithCounterTaskAdditionalInformationDTO.SERIALIZATION_MODULE); + static final Hostname HOSTNAME = new Hostname("foo"); + static final Hostname HOSTNAME_2 = new Hostname("bar"); + @RegisterExtension + static final RabbitMQExtension RABBIT_MQ_EXTENSION = RabbitMQExtension.singletonRabbitMQ(); - static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension( + @RegisterExtension + static final CassandraClusterExtension CASSANDRA_CLUSTER = new CassandraClusterExtension( CassandraModule.aggregateModules( CassandraSchemaVersionModule.MODULE, CassandraEventStoreModule.MODULE, CassandraZonedDateTimeModule.MODULE, CassandraTaskExecutionDetailsProjectionModule.MODULE())); - @RegisterExtension - static RabbitMQExtension rabbitMQExtension = RabbitMQExtension.singletonRabbitMQ(); + JsonTaskSerializer taskSerializer = new JsonTaskSerializer( + TestTaskDTOModules.COMPLETED_TASK_MODULE, + TestTaskDTOModules.FAILED_TASK_MODULE, + TestTaskDTOModules.THROWING_TASK_MODULE, + TestTaskDTOModules.MEMORY_REFERENCE_TASK_MODULE.apply(new MemoryReferenceTaskStore()), + TestTaskDTOModules.MEMORY_REFERENCE_WITH_COUNTER_TASK_MODULE.apply(new MemoryReferenceWithCounterTaskStore())); - @RegisterExtension - static CassandraEventStoreExtension eventStoreExtension = new CassandraEventStoreExtension(cassandraCluster, MODULES); + Set<EventDTOModule<?, ?>> eventDtoModule = TasksSerializationModule.list(taskSerializer, JSON_TASK_ADDITIONAL_INFORMATION_SERIALIZER).stream().collect(Guavate.toImmutableSet()); @RegisterExtension - static CountDownLatchExtension countDownLatchExtension = new CountDownLatchExtension(); + CassandraEventStoreExtension eventStoreExtension = new CassandraEventStoreExtension(CASSANDRA_CLUSTER, eventDtoModule); - private final CassandraCluster cassandra = cassandraCluster.getCassandraCluster(); - private final CassandraTaskExecutionDetailsProjectionDAO cassandraTaskExecutionDetailsProjectionDAO = new CassandraTaskExecutionDetailsProjectionDAO(cassandra.getConf(), cassandra.getTypesProvider(), JSON_TASK_ADDITIONAL_INFORMATION_SERIALIZER); - private final TaskExecutionDetailsProjection executionDetailsProjection = new CassandraTaskExecutionDetailsProjection(cassandraTaskExecutionDetailsProjectionDAO); + @RegisterExtension + CountDownLatchExtension countDownLatchExtension = new CountDownLatchExtension(); - private TrackedRabbitMQWorkQueueSupplier workQueueSupplier; - private EventStore eventStore; - private List<RabbitMQTerminationSubscriber> terminationSubscribers; + TrackedRabbitMQWorkQueueSupplier workQueueSupplier; + EventStore eventStore; + List<RabbitMQTerminationSubscriber> terminationSubscribers; + TaskExecutionDetailsProjection executionDetailsProjection; + JsonEventSerializer eventSerializer; @BeforeEach void setUp(EventStore eventStore) { - workQueueSupplier = new TrackedRabbitMQWorkQueueSupplier(rabbitMQExtension.getRabbitChannelPool(), TASK_SERIALIZER); + CassandraCluster cassandra = CASSANDRA_CLUSTER.getCassandraCluster(); + CassandraTaskExecutionDetailsProjectionDAO projectionDAO = new CassandraTaskExecutionDetailsProjectionDAO(cassandra.getConf(), cassandra.getTypesProvider(), JSON_TASK_ADDITIONAL_INFORMATION_SERIALIZER); + this.executionDetailsProjection = new CassandraTaskExecutionDetailsProjection(projectionDAO); + this.workQueueSupplier = new TrackedRabbitMQWorkQueueSupplier(RABBIT_MQ_EXTENSION.getRabbitChannelPool(), taskSerializer); this.eventStore = eventStore; - terminationSubscribers = new ArrayList<>(); + this.terminationSubscribers = new ArrayList<>(); + this.eventSerializer = new JsonEventSerializer(eventDtoModule); } @AfterEach @@ -153,8 +154,8 @@ class DistributedTaskManagerTest implements TaskManagerContract { return taskManager(HOSTNAME); } - private EventSourcingTaskManager taskManager(Hostname hostname) { - RabbitMQTerminationSubscriber terminationSubscriber = new RabbitMQTerminationSubscriber(rabbitMQExtension.getRabbitChannelPool(), EVENT_SERIALIZER); + EventSourcingTaskManager taskManager(Hostname hostname) { + RabbitMQTerminationSubscriber terminationSubscriber = new RabbitMQTerminationSubscriber(RABBIT_MQ_EXTENSION.getRabbitChannelPool(), eventSerializer); terminationSubscribers.add(terminationSubscriber); terminationSubscriber.start(); return new EventSourcingTaskManager(workQueueSupplier, eventStore, executionDetailsProjection, hostname, terminationSubscriber); @@ -177,7 +178,7 @@ class DistributedTaskManagerTest implements TaskManagerContract { } @Test - void givenTwoTaskManagersAndTwoTaskOnlyOneTaskShouldRunAtTheSameTime() throws InterruptedException { + void givenTwoTaskManagersAndTwoTaskOnlyOneTaskShouldRunAtTheSameTime() { CountDownLatch waitingForFirstTaskLatch = new CountDownLatch(1); try (EventSourcingTaskManager taskManager1 = taskManager(); diff --git a/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/TaskEventsSerializationTest.java b/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/TaskEventsSerializationTest.java index bcb2a6d..1ad3921 100644 --- a/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/TaskEventsSerializationTest.java +++ b/server/task/task-distributed/src/test/java/org/apache/james/task/eventsourcing/distributed/TaskEventsSerializationTest.java @@ -22,12 +22,10 @@ package org.apache.james.task.eventsourcing.distributed; import static org.assertj.core.api.Assertions.assertThat; import java.time.Instant; -import java.util.Set; import java.util.stream.Stream; import org.apache.james.eventsourcing.EventId; import org.apache.james.eventsourcing.eventstore.cassandra.JsonEventSerializer; -import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule; import org.apache.james.server.task.json.JsonTaskAdditionalInformationSerializer; import org.apache.james.server.task.json.JsonTaskSerializer; import org.apache.james.server.task.json.dto.MemoryReferenceWithCounterTaskAdditionalInformationDTO; @@ -50,44 +48,47 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import com.github.steveash.guavate.Guavate; import net.javacrumbs.jsonunit.assertj.JsonAssertions; import scala.Option; class TaskEventsSerializationTest { - private static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); - private static final JsonTaskSerializer TASK_SERIALIZER = new JsonTaskSerializer(TestTaskDTOModules.COMPLETED_TASK_MODULE, - TestTaskDTOModules.MEMORY_REFERENCE_WITH_COUNTER_TASK_MODULE.apply(new MemoryReferenceWithCounterTaskStore())); - private static final JsonTaskAdditionalInformationSerializer TASK_ADDITIONNAL_INFORMATION_SERIALIZER = new JsonTaskAdditionalInformationSerializer(MemoryReferenceWithCounterTaskAdditionalInformationDTO.SERIALIZATION_MODULE); - private static final Set<EventDTOModule<?, ?>> MODULES = TasksSerializationModule.list(TASK_SERIALIZER, TASK_ADDITIONNAL_INFORMATION_SERIALIZER); - private static final JsonEventSerializer SERIALIZER = new JsonEventSerializer(MODULES.stream().collect(Guavate.toImmutableSet())); - private static final TaskAggregateId AGGREGATE_ID = new TaskAggregateId(TaskId.fromString("2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd")); - private static final EventId EVENT_ID = EventId.fromSerialized(42); - private static final Task TASK = new CompletedTask(); - private static final Hostname HOSTNAME = new Hostname("foo"); - private static final MemoryReferenceWithCounterTask.AdditionalInformation counterAdditionalInformation = new MemoryReferenceWithCounterTask.AdditionalInformation(3, TIMESTAMP); + static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); + static final JsonTaskAdditionalInformationSerializer TASK_ADDITIONNAL_INFORMATION_SERIALIZER = new JsonTaskAdditionalInformationSerializer(MemoryReferenceWithCounterTaskAdditionalInformationDTO.SERIALIZATION_MODULE); + static final TaskAggregateId AGGREGATE_ID = new TaskAggregateId(TaskId.fromString("2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd")); + static final EventId EVENT_ID = EventId.fromSerialized(42); + static final Task TASK = new CompletedTask(); + static final Hostname HOSTNAME = new Hostname("foo"); + static final MemoryReferenceWithCounterTask.AdditionalInformation COUNTER_ADDITIONAL_INFORMATION = new MemoryReferenceWithCounterTask.AdditionalInformation(3, TIMESTAMP); + + JsonEventSerializer serializer = + new JsonEventSerializer( + TasksSerializationModule.list( + new JsonTaskSerializer( + TestTaskDTOModules.COMPLETED_TASK_MODULE, + TestTaskDTOModules.MEMORY_REFERENCE_WITH_COUNTER_TASK_MODULE.apply(new MemoryReferenceWithCounterTaskStore())), + TASK_ADDITIONNAL_INFORMATION_SERIALIZER)); @ParameterizedTest @MethodSource void taskShouldBeSerializable(TaskEvent event, String serializedJson) throws Exception { - JsonAssertions.assertThatJson(SERIALIZER.serialize(event)).isEqualTo(serializedJson); + JsonAssertions.assertThatJson(serializer.serialize(event)).isEqualTo(serializedJson); } - private static Stream<Arguments> taskShouldBeSerializable() throws Exception { + static Stream<Arguments> taskShouldBeSerializable() throws Exception { return validTasks(); } @ParameterizedTest @MethodSource void taskShouldBeDeserializable(TaskEvent event, String serializedJson) throws Exception { - assertThat(SERIALIZER.deserialize(serializedJson)).isEqualToComparingFieldByFieldRecursively(event); + assertThat(serializer.deserialize(serializedJson)).isEqualToComparingFieldByFieldRecursively(event); } - private static Stream<Arguments> taskShouldBeDeserializable() throws Exception { + static Stream<Arguments> taskShouldBeDeserializable() throws Exception { return validTasks(); } - private static Stream<Arguments> validTasks() throws Exception { + static Stream<Arguments> validTasks() throws Exception { return Stream.of( Arguments.of(new Created(AGGREGATE_ID, EVENT_ID, TASK, HOSTNAME), "{\"task\":\"{\\\"type\\\":\\\"completed-task\\\"}\",\"type\":\"task-manager-created\",\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"hostname\":\"foo\"}\n"), Arguments.of(new Started(AGGREGATE_ID, EVENT_ID, HOSTNAME), "{\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-started\",\"hostname\":\"foo\"}"), @@ -97,10 +98,10 @@ class TaskEventsSerializationTest { Arguments.of(new Failed(AGGREGATE_ID, EVENT_ID, Option.empty(), Option.empty(), Option.empty()), "{\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-failed\"}"), Arguments.of(new Failed(AGGREGATE_ID, EVENT_ID, Option.empty(), Option.apply("contextual message"), Option.apply("my exception")), "{\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-failed\", \"errorMessage\": \"contextual message\", \"exception\": \"my exception\"}"), Arguments.of(new Cancelled(AGGREGATE_ID, EVENT_ID, Option.empty()), "{\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-cancelled\"}"), - Arguments.of(new Completed(AGGREGATE_ID, EVENT_ID, Task.Result.COMPLETED, Option.apply(counterAdditionalInformation)), "{\"result\":\"COMPLETED\",\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-completed\",\"additionalInformation\":\"{\\\"type\\\":\\\"memory-reference-task-with-counter\\\",\\\"count\\\":3,\\\"timestamp\\\":\\\"2018-11-13T12:00:55Z\\\"}\"}"), - Arguments.of(new Completed(AGGREGATE_ID, EVENT_ID, Task.Result.PARTIAL, Option.apply(counterAdditionalInformation)), "{\"result\":\"PARTIAL\",\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-completed\",\"additionalInformation\":\"{\\\"type\\\":\\\"memory-reference-task-with-counter\\\",\\\"count\\\":3,\\\"timestamp\\\":\\\"2018-11-13T12:00:55Z\\\"}\"}"), - Arguments.of(new Failed(AGGREGATE_ID, EVENT_ID, Option.apply(counterAdditionalInformation), Option.empty(), Option.empty()), "{\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-failed\",\"additionalInformation\":\"{\\\"type\\\":\\\"memory-reference-task-with-counter\\\",\\\"count\\\":3,\\\"timestamp\\\":\\\"2018-11-13T12:00:55Z\\\"}\"}"), - Arguments.of(new Cancelled(AGGREGATE_ID, EVENT_ID, Option.apply(counterAdditionalInformation)), "{\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-cancelled\",\"additionalInformation\":\"{\\\"type\\\":\\\"memory-reference-task-with-counter\\\",\\\"count\\\":3,\\\"timestamp\\\":\\\"2018-11-13T12:00:55Z\\\"}\"}") + Arguments.of(new Completed(AGGREGATE_ID, EVENT_ID, Task.Result.COMPLETED, Option.apply(COUNTER_ADDITIONAL_INFORMATION)), "{\"result\":\"COMPLETED\",\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-completed\",\"additionalInformation\":\"{\\\"type\\\":\\\"memory-reference-task-with-counter\\\",\\\"count\\\":3,\\\"timestamp\\\":\\\"2018-11-13T12:00:55Z\\\"}\"}"), + Arguments.of(new Completed(AGGREGATE_ID, EVENT_ID, Task.Result.PARTIAL, Option.apply(COUNTER_ADDITIONAL_INFORMATION)), "{\"result\":\"PARTIAL\",\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-completed\",\"additionalInformation\":\"{\\\"type\\\":\\\"memory-reference-task-with-counter\\\",\\\"count\\\":3,\\\"timestamp\\\":\\\"2018-11-13T12:00:55Z\\\"}\"}"), + Arguments.of(new Failed(AGGREGATE_ID, EVENT_ID, Option.apply(COUNTER_ADDITIONAL_INFORMATION), Option.empty(), Option.empty()), "{\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-failed\",\"additionalInformation\":\"{\\\"type\\\":\\\"memory-reference-task-with-counter\\\",\\\"count\\\":3,\\\"timestamp\\\":\\\"2018-11-13T12:00:55Z\\\"}\"}"), + Arguments.of(new Cancelled(AGGREGATE_ID, EVENT_ID, Option.apply(COUNTER_ADDITIONAL_INFORMATION)), "{\"aggregate\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"event\":42,\"type\":\"task-manager-cancelled\",\"additionalInformation\":\"{\\\"type\\\":\\\"memory-reference-task-with-counter\\\",\\\"count\\\":3,\\\"timestamp\\\":\\\"2018-11-13T12:00:55Z\\\"}\"}") ); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
