Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[56] Readme badge update #73

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/robo4j-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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/?package=jdk#zulu
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,6 +87,8 @@ void simpleHttpNonUnitTest() throws Exception {
/* client system sending a messages to the main system */
RoboReference<Object> 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);

Expand Down Expand Up @@ -194,7 +197,12 @@ private RoboContext getClientRoboSystem() throws Exception {
}

private static <T, R> R getAttributeOrTimeout(RoboReference<T> roboReference, AttributeDescriptor<R> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> {
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<CountDownLatch> DESCRIPTOR_MESSAGES_LATCH = DefaultAttributeDescriptor
.create(CountDownLatch.class, ATTR_MESSAGES_LATCH);
public static final DefaultAttributeDescriptor<Integer> DESCRIPTOR_MESSAGES_TOTAL = DefaultAttributeDescriptor
.create(Integer.class, ATTR_MESSAGES_TOTAL);
public static final DefaultAttributeDescriptor<List> DESCRIPTOR_RECEIVED_MESSAGES = DefaultAttributeDescriptor
.create(List.class, ATTR_RECEIVED_MESSAGES);
public static final DefaultAttributeDescriptor<CountDownLatch> DESCRIPTOR_MESSAGES_LATCH = DefaultAttributeDescriptor
.create(CountDownLatch.class, ATTR_MESSAGES_LATCH);
public static final DefaultAttributeDescriptor<Integer> DESCRIPTOR_MESSAGES_TOTAL = DefaultAttributeDescriptor
.create(Integer.class, ATTR_MESSAGES_TOTAL);

private static final int DEFAULT = 0;
private volatile AtomicInteger counter;
private List<String> receivedMessages = Collections.synchronizedList(new ArrayList<>());
private CountDownLatch messagesLatch;
private static final int DEFAULT = 0;
private final AtomicInteger counter = new AtomicInteger(DEFAULT);
private final List<String> 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> R onGetAttribute(AttributeDescriptor<R> 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> R onGetAttribute(AttributeDescriptor<R> 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;
}

}
Loading