deps: Refactor dependencies (#3224)

* remove spring dep
move junit, logging, mockito under dep mgmt

* upgrade anti-corruption-layer deps

* async method invocation

* balking, bloc

* bridge to bytecode

* caching

* callback - cqrs

* component - health check

* hexagonal - metadata mapping

* rest of the patterns

* remove checkstyle, take spotless into use
This commit is contained in:
Ilkka Seppälä
2025-03-29 19:34:27 +02:00
committed by GitHub
parent 371439aeaa
commit 0ca162a55c
1863 changed files with 14408 additions and 17637 deletions
@@ -51,10 +51,7 @@ package com.iluwatar.databus;
import lombok.Getter;
import lombok.Setter;
/**
* Base for data to send via the Data-Bus.
*
*/
/** Base for data to send via the Data-Bus. */
@Getter
@Setter
public class AbstractDataType implements DataType {
@@ -35,26 +35,25 @@ import java.time.LocalDateTime;
* The Data Bus pattern.
*
* @see <a href="http://wiki.c2.com/?DataBusPattern">http://wiki.c2.com/?DataBusPattern</a>
* <p>The Data-Bus pattern provides a method where different parts of an application may
* pass messages between each other without needing to be aware of the other's existence.</p>
* <p>The Data-Bus pattern provides a method where different parts of an application may pass
* messages between each other without needing to be aware of the other's existence.
* <p>Similar to the {@code ObserverPattern}, members register themselves with the {@link
* DataBus} and may then receive each piece of data that is published to the Data-Bus. The
* member may react to any given message or not.</p>
* <p>It allows for Many-to-Many distribution of data, as there may be any number of
* publishers to a Data-Bus, and any number of members receiving the data. All members will
* receive the same data, the order each receives a given piece of data, is an implementation
* detail.</p>
* <p>Members may unsubscribe from the Data-Bus to stop receiving data.</p>
* <p>This example of the pattern implements a Synchronous Data-Bus, meaning that
* when data is published to the Data-Bus, the publish method will not return until all members
* have received the data and returned.</p>
* <p>The {@link DataBus} class is a Singleton.</p>
* <p>Members of the Data-Bus must implement the {@link Member} interface.</p>
* <p>Data to be published via the Data-Bus must implement the {@link DataType} interface.</p>
* <p>The {@code data} package contains example {@link DataType} implementations.</p>
* <p>The {@code members} package contains example {@link Member} implementations.</p>
* <p>The {@link StatusMember} demonstrates using the DataBus to publish a message
* to the Data-Bus when it receives a message.</p>
* member may react to any given message or not.
* <p>It allows for Many-to-Many distribution of data, as there may be any number of publishers
* to a Data-Bus, and any number of members receiving the data. All members will receive the
* same data, the order each receives a given piece of data, is an implementation detail.
* <p>Members may unsubscribe from the Data-Bus to stop receiving data.
* <p>This example of the pattern implements a Synchronous Data-Bus, meaning that when data is
* published to the Data-Bus, the publish method will not return until all members have received
* the data and returned.
* <p>The {@link DataBus} class is a Singleton.
* <p>Members of the Data-Bus must implement the {@link Member} interface.
* <p>Data to be published via the Data-Bus must implement the {@link DataType} interface.
* <p>The {@code data} package contains example {@link DataType} implementations.
* <p>The {@code members} package contains example {@link Member} implementations.
* <p>The {@link StatusMember} demonstrates using the DataBus to publish a message to the
* Data-Bus when it receives a message.
*/
class App {
@@ -30,8 +30,7 @@ import java.util.Set;
/**
* The Data-Bus implementation.
*
* <p>This implementation uses a Singleton.</p>
*
* <p>This implementation uses a Singleton.
*/
public class DataBus {
@@ -48,11 +48,7 @@ SOFTWARE.
package com.iluwatar.databus;
/**
* Events are sent via the Data-Bus.
*
*/
/** Events are sent via the Data-Bus. */
public interface DataType {
/**
@@ -50,10 +50,7 @@ package com.iluwatar.databus;
import java.util.function.Consumer;
/**
* Members receive events from the Data-Bus.
*
*/
/** Members receive events from the Data-Bus. */
public interface Member extends Consumer<DataType> {
void accept(DataType event);
@@ -29,10 +29,7 @@ import com.iluwatar.databus.DataType;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* An event raised when a string message is sent.
*
*/
/** An event raised when a string message is sent. */
@Getter
@AllArgsConstructor
public class MessageData extends AbstractDataType {
@@ -30,10 +30,7 @@ import java.time.LocalDateTime;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* An event raised when applications starts, containing the start time of the application.
*
*/
/** An event raised when applications starts, containing the start time of the application. */
@RequiredArgsConstructor
@Getter
public class StartingData extends AbstractDataType {
@@ -30,10 +30,7 @@ import java.time.LocalDateTime;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* An event raised when applications stops, containing the stop time of the application.
*
*/
/** An event raised when applications stops, containing the stop time of the application. */
@RequiredArgsConstructor
@Getter
public class StoppingData extends AbstractDataType {
@@ -31,10 +31,7 @@ import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
/**
* Receiver of Data-Bus events that collects the messages from each {@link MessageData}.
*
*/
/** Receiver of Data-Bus events that collects the messages from each {@link MessageData}. */
@Slf4j
public class MessageCollectorMember implements Member {
@@ -34,10 +34,7 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* Receiver of Data-Bus events.
*
*/
/** Receiver of Data-Bus events. */
@Getter
@Slf4j
@RequiredArgsConstructor
@@ -69,5 +66,4 @@ public class StatusMember implements Member {
LOGGER.info("Receiver {} sending goodbye message", id);
data.getDataBus().publish(MessageData.of(String.format("Goodbye cruel world from #%d!", id)));
}
}
@@ -32,17 +32,12 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Tests for {@link DataBus}.
*
*/
/** Tests for {@link DataBus}. */
class DataBusTest {
@Mock
private Member member;
@Mock private Member member;
@Mock
private DataType event;
@Mock private DataType event;
@BeforeEach
void setUp() {
@@ -51,25 +46,24 @@ class DataBusTest {
@Test
void publishedEventIsReceivedBySubscribedMember() {
//given
// given
final var dataBus = DataBus.getInstance();
dataBus.subscribe(member);
//when
// when
dataBus.publish(event);
//then
// then
then(member).should().accept(event);
}
@Test
void publishedEventIsNotReceivedByMemberAfterUnsubscribing() {
//given
// given
final var dataBus = DataBus.getInstance();
dataBus.subscribe(member);
dataBus.unsubscribe(member);
//when
// when
dataBus.publish(event);
//then
// then
then(member).should(never()).accept(event);
}
}
@@ -32,33 +32,29 @@ import com.iluwatar.databus.data.StartingData;
import java.time.LocalDateTime;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link MessageCollectorMember}.
*
*/
/** Tests for {@link MessageCollectorMember}. */
class MessageCollectorMemberTest {
@Test
void collectMessageFromMessageData() {
//given
// given
final var message = "message";
final var messageData = new MessageData(message);
final var collector = new MessageCollectorMember("collector");
//when
// when
collector.accept(messageData);
//then
// then
assertTrue(collector.getMessages().contains(message));
}
@Test
void collectIgnoresMessageFromOtherDataTypes() {
//given
// given
final var startingData = new StartingData(LocalDateTime.now());
final var collector = new MessageCollectorMember("collector");
//when
// when
collector.accept(startingData);
//then
// then
assertEquals(0, collector.getMessages().size());
}
}
@@ -35,47 +35,43 @@ import java.time.LocalDateTime;
import java.time.Month;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link StatusMember}.
*
*/
/** Tests for {@link StatusMember}. */
class StatusMemberTest {
@Test
void statusRecordsTheStartTime() {
//given
// given
final var startTime = LocalDateTime.of(2017, Month.APRIL, 1, 19, 9);
final var startingData = new StartingData(startTime);
final var statusMember = new StatusMember(1);
//when
// when
statusMember.accept(startingData);
//then
// then
assertEquals(startTime, statusMember.getStarted());
}
@Test
void statusRecordsTheStopTime() {
//given
// given
final var stop = LocalDateTime.of(2017, Month.APRIL, 1, 19, 12);
final var stoppingData = new StoppingData(stop);
stoppingData.setDataBus(DataBus.getInstance());
final var statusMember = new StatusMember(1);
//when
// when
statusMember.accept(stoppingData);
//then
// then
assertEquals(stop, statusMember.getStopped());
}
@Test
void statusIgnoresMessageData() {
//given
// given
final var messageData = new MessageData("message");
final var statusMember = new StatusMember(1);
//when
// when
statusMember.accept(messageData);
//then
// then
assertNull(statusMember.getStarted());
assertNull(statusMember.getStopped());
}
}