From 1ddc633624154ba1d847a5550bb08bce3b086ae0 Mon Sep 17 00:00:00 2001 From: Miro Wengner Date: Fri, 4 Oct 2024 09:49:38 +0200 Subject: [PATCH 1/3] [56] update test and readme --- README.md | 2 +- .../http/test/units/RoboHttpDynamicTests.java | 9 +- .../test/units/config/StringConsumer.java | 115 ++++++++---------- 3 files changed, 62 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 8000032f..301bb94f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Robo4j-master](https://github.com/Robo4j/robo4j/actions/workflows/robo4j-build-actions.yml/badge.svg?branch=master) +![Robo4j-master](https://github.com/Robo4j/robo4j/actions/workflows/robo4j-verification.yml/badge.svg?branch=master) # Robo4J Robo4J provides an easy way of getting started with building custom hardware and creating software for it running on the JVM. diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java index 663e256c..347ee20b 100644 --- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java +++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java @@ -19,6 +19,7 @@ import com.robo4j.*; import com.robo4j.configuration.Configuration; import com.robo4j.configuration.ConfigurationBuilder; +import com.robo4j.logging.SimpleLoggingUtil; import com.robo4j.socket.http.HttpMethod; import com.robo4j.socket.http.HttpVersion; import com.robo4j.socket.http.message.HttpDecoratedRequest; @@ -86,6 +87,7 @@ void simpleHttpNonUnitTest() throws Exception { /* client system sending a messages to the main system */ RoboReference decoratedProducer = clientSystem.getReference(DECORATED_PRODUCER); decoratedProducer.sendMessage(MESSAGES_NUMBER); + CountDownLatch countDownLatchDecoratedProducer = getAttributeOrTimeout(decoratedProducer, SocketMessageDecoratedProducerUnit.DESCRIPTOR_MESSAGES_LATCH); var messagesProduced = countDownLatchDecoratedProducer.await(TIMEOUT, TIME_UNIT); @@ -194,7 +196,12 @@ private RoboContext getClientRoboSystem() throws Exception { } private static R getAttributeOrTimeout(RoboReference roboReference, AttributeDescriptor attributeDescriptor) throws InterruptedException, ExecutionException, TimeoutException { - return roboReference.getAttribute(attributeDescriptor).get(TIMEOUT, TimeUnit.MINUTES); + var attribute = roboReference.getAttribute(attributeDescriptor).get(TIMEOUT, TimeUnit.MINUTES); + if (attribute == null) { + SimpleLoggingUtil.error(RoboHttpDynamicTests.class, "roboReference:" + roboReference.getId() + ", no attribute:" + attributeDescriptor.getAttributeName()); + attribute = roboReference.getAttribute(attributeDescriptor).get(TIMEOUT, TimeUnit.MINUTES); + } + return attribute; } } diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/StringConsumer.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/StringConsumer.java index 3ca60382..56723451 100644 --- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/StringConsumer.java +++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/StringConsumer.java @@ -16,11 +16,7 @@ */ package com.robo4j.socket.http.test.units.config; -import com.robo4j.AttributeDescriptor; -import com.robo4j.ConfigurationException; -import com.robo4j.DefaultAttributeDescriptor; -import com.robo4j.RoboContext; -import com.robo4j.RoboUnit; +import com.robo4j.*; import com.robo4j.configuration.Configuration; import java.util.ArrayList; @@ -30,73 +26,68 @@ import java.util.concurrent.atomic.AtomicInteger; /** - * * @author Marcus Hirt (@hirt) * @author Miroslav Wengner (@miragemiko) */ -@SuppressWarnings("rawtypes") public class StringConsumer extends RoboUnit { - public static final String NAME = "stringConsumer"; - public static final String ATTR_MESSAGES_TOTAL = "getNumberOfSentMessages"; - public static final String ATTR_RECEIVED_MESSAGES = "getReceivedMessages"; - public static final String ATTR_MESSAGES_LATCH = "messagesLatch"; - public static final String PROP_TOTAL_NUMBER_MESSAGES = "totalNumberMessages"; + public static final String NAME = "stringConsumer"; + public static final String ATTR_MESSAGES_TOTAL = "getNumberOfSentMessages"; + public static final String ATTR_RECEIVED_MESSAGES = "getReceivedMessages"; + public static final String ATTR_MESSAGES_LATCH = "messagesLatch"; + public static final String PROP_TOTAL_NUMBER_MESSAGES = "totalNumberMessages"; - public static final DefaultAttributeDescriptor DESCRIPTOR_MESSAGES_LATCH = DefaultAttributeDescriptor - .create(CountDownLatch.class, ATTR_MESSAGES_LATCH); - public static final DefaultAttributeDescriptor DESCRIPTOR_MESSAGES_TOTAL = DefaultAttributeDescriptor - .create(Integer.class, ATTR_MESSAGES_TOTAL); - public static final DefaultAttributeDescriptor DESCRIPTOR_RECEIVED_MESSAGES = DefaultAttributeDescriptor - .create(List.class, ATTR_RECEIVED_MESSAGES); + public static final DefaultAttributeDescriptor DESCRIPTOR_MESSAGES_LATCH = DefaultAttributeDescriptor + .create(CountDownLatch.class, ATTR_MESSAGES_LATCH); + public static final DefaultAttributeDescriptor DESCRIPTOR_MESSAGES_TOTAL = DefaultAttributeDescriptor + .create(Integer.class, ATTR_MESSAGES_TOTAL); - private static final int DEFAULT = 0; - private volatile AtomicInteger counter; - private List receivedMessages = Collections.synchronizedList(new ArrayList<>()); - private CountDownLatch messagesLatch; + private static final int DEFAULT = 0; + private final AtomicInteger counter = new AtomicInteger(DEFAULT); + private final List receivedMessages = Collections.synchronizedList(new ArrayList<>()); + private CountDownLatch messagesLatch; - /** - * @param context - * @param id - */ - public StringConsumer(RoboContext context, String id) { - super(String.class, context, id); - this.counter = new AtomicInteger(DEFAULT); - } + /** + * @param context robo4j context + * @param id unit id + */ + public StringConsumer(RoboContext context, String id) { + super(String.class, context, id); + } - @Override - protected void onInitialization(Configuration configuration) throws ConfigurationException { - int totalNumber = configuration.getInteger(PROP_TOTAL_NUMBER_MESSAGES, 0); - if (totalNumber > 0) { - messagesLatch = new CountDownLatch(totalNumber); - } - } + @Override + protected void onInitialization(Configuration configuration) throws ConfigurationException { + int totalNumber = configuration.getInteger(PROP_TOTAL_NUMBER_MESSAGES, 0); + if (totalNumber > 0) { + messagesLatch = new CountDownLatch(totalNumber); + } + } - @Override - public void onMessage(String message) { - counter.incrementAndGet(); - receivedMessages.add(message); - if (messagesLatch != null) { - messagesLatch.countDown(); - } - } + @Override + public void onMessage(String message) { + counter.incrementAndGet(); + receivedMessages.add(message); + if (messagesLatch != null) { + messagesLatch.countDown(); + } + } - @SuppressWarnings("unchecked") - @Override - public synchronized R onGetAttribute(AttributeDescriptor attribute) { - if (attribute.getAttributeName().equals(ATTR_MESSAGES_TOTAL) - && attribute.getAttributeType() == Integer.class) { - return (R) Integer.valueOf(counter.get()); - } - if (attribute.getAttributeName().equals(ATTR_RECEIVED_MESSAGES) - && attribute.getAttributeType() == List.class) { - return (R) receivedMessages; - } - if (attribute.getAttributeName().equals(ATTR_MESSAGES_LATCH) - && attribute.getAttributeType() == CountDownLatch.class) { - return (R) messagesLatch; - } - return null; - } + @SuppressWarnings("unchecked") + @Override + public synchronized R onGetAttribute(AttributeDescriptor attribute) { + if (attribute.getAttributeName().equals(ATTR_MESSAGES_TOTAL) + && attribute.getAttributeType() == Integer.class) { + return (R) Integer.valueOf(counter.get()); + } + if (attribute.getAttributeName().equals(ATTR_RECEIVED_MESSAGES) + && attribute.getAttributeType() == List.class) { + return (R) receivedMessages; + } + if (attribute.getAttributeName().equals(ATTR_MESSAGES_LATCH) + && attribute.getAttributeType() == CountDownLatch.class) { + return (R) messagesLatch; + } + return null; + } } From 309512485379b7f66408c52cc004c0817d2c232f Mon Sep 17 00:00:00 2001 From: Miro Wengner Date: Fri, 4 Oct 2024 10:03:24 +0200 Subject: [PATCH 2/3] [56] update test and readme --- README.md | 2 +- .../com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 301bb94f..de43b650 100644 --- a/README.md +++ b/README.md @@ -61,4 +61,4 @@ Robo4J is released under [General Public License][] v3. [Git]: https://git-scm.com/ [Robo4j documentation]: https://www.robo4j.io/p/documentation.html [Liberica JDK]: https://www.bell-sw.com/java.html -[Azul Zulu Embedded]: https://www.azul.com/downloads/zulu-embedded/ +[Azul Zulu]: https://www.azul.com/downloads/zulu-embedded/ diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java index 347ee20b..e0c909be 100644 --- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java +++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java @@ -88,6 +88,7 @@ void simpleHttpNonUnitTest() throws Exception { RoboReference decoratedProducer = clientSystem.getReference(DECORATED_PRODUCER); decoratedProducer.sendMessage(MESSAGES_NUMBER); + // TODO: review how to receiving attributes CountDownLatch countDownLatchDecoratedProducer = getAttributeOrTimeout(decoratedProducer, SocketMessageDecoratedProducerUnit.DESCRIPTOR_MESSAGES_LATCH); var messagesProduced = countDownLatchDecoratedProducer.await(TIMEOUT, TIME_UNIT); From 7f3f66960c8383eb9f40b62a08efd0f6d0517c93 Mon Sep 17 00:00:00 2001 From: Frank Delporte Date: Fri, 4 Oct 2024 12:11:19 +0200 Subject: [PATCH 3/3] Link to Zulu + Zulu in workflow --- .github/workflows/robo4j-verification.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/robo4j-verification.yml b/.github/workflows/robo4j-verification.yml index bca2b1df..289dcdfb 100644 --- a/.github/workflows/robo4j-verification.yml +++ b/.github/workflows/robo4j-verification.yml @@ -14,7 +14,7 @@ jobs: - name: Setup Java 21 uses: actions/setup-java@v4 with: - distribution: 'temurin' + distribution: 'zulu' java-version: '21' java-package: 'jdk' mvn-toolchain-id: 'JavaSE-21' diff --git a/README.md b/README.md index de43b650..011c4984 100644 --- a/README.md +++ b/README.md @@ -61,4 +61,4 @@ Robo4J is released under [General Public License][] v3. [Git]: https://git-scm.com/ [Robo4j documentation]: https://www.robo4j.io/p/documentation.html [Liberica JDK]: https://www.bell-sw.com/java.html -[Azul Zulu]: https://www.azul.com/downloads/zulu-embedded/ +[Azul Zulu]: https://www.azul.com/downloads/?package=jdk#zulu