use of io.envoyproxy.envoy.config.core.v3.Node in project ignite by apache.
the class GridConcurrentLinkedDequeMultiThreadedTest method testQueueMultiThreaded.
/**
* @throws Exception If failed.
*/
@Test
public void testQueueMultiThreaded() throws Exception {
final AtomicBoolean done = new AtomicBoolean();
final ConcurrentLinkedDeque8<Byte> queue = new ConcurrentLinkedDeque8<>();
// Poll thread.
IgniteInternalFuture<?> pollFut = multithreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
info("Thread started.");
while (!done.get()) try {
queue.poll();
} catch (Throwable t) {
error("Error in poll thread.", t);
done.set(true);
}
info("Thread finished.");
return null;
}
}, 5, "queue-poll");
// Producer thread.
IgniteInternalFuture<?> prodFut = multithreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
info("Thread started.");
while (!done.get()) {
Node<Byte> n = queue.addx((byte) 1);
if (RND.nextBoolean())
queue.unlinkx(n);
}
info("Thread finished.");
return null;
}
}, 5, "queue-prod");
Thread.sleep(20 * 1000);
done.set(true);
pollFut.get();
prodFut.get();
}
use of io.envoyproxy.envoy.config.core.v3.Node in project smarthome by eclipse.
the class HomieImplementationTests method retrieveAttributes.
@SuppressWarnings("null")
@Test
public void retrieveAttributes() throws InterruptedException, ExecutionException {
assertThat(connection.hasSubscribers(), is(false));
Node node = new Node(deviceTopic, "testnode", ThingChannelConstants.testHomieThing, callback, new NodeAttributes());
Property property = spy(new Property(deviceTopic + "/testnode", node, "temperature", callback, new PropertyAttributes()));
// Create a scheduler
ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(4);
property.subscribe(connection, scheduler, 100).get();
assertThat(property.attributes.settable, is(true));
assertThat(property.attributes.retained, is(true));
assertThat(property.attributes.name, is("Testprop"));
assertThat(property.attributes.unit, is("°C"));
assertThat(property.attributes.datatype, is(DataTypeEnum.float_));
assertThat(property.attributes.format, is("-100:100"));
verify(property).attributesReceived();
// Receive property value
ChannelState channelState = spy(property.getChannelState());
PropertyHelper.setChannelState(property, channelState);
property.startChannel(connection, scheduler, 200).get();
verify(channelState).start(any(), any(), anyInt());
verify(channelState).processMessage(any(), any());
verify(callback).updateChannelState(any(), any());
assertThat(property.getChannelState().getCache().getChannelState(), is(new DecimalType(10)));
property.stop().get();
assertThat(connection.hasSubscribers(), is(false));
}
use of io.envoyproxy.envoy.config.core.v3.Node in project smarthome by eclipse.
the class HomieThingHandlerTests method handleCommandRefresh.
@SuppressWarnings("null")
@Test
public void handleCommandRefresh() {
// Create mocked homie device tree with one node and one read-only property
Node node = thingHandler.device.createNode("node", spy(new NodeAttributes()));
doReturn(future).when(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(node.attributes).unsubscribe();
node.attributes.name = "testnode";
Property property = node.createProperty("property", spy(new PropertyAttributes()));
doReturn(future).when(property.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(property.attributes).unsubscribe();
property.attributes.name = "testprop";
property.attributes.datatype = DataTypeEnum.string_;
property.attributes.settable = false;
property.attributesReceived();
node.properties.put(property.propertyID, property);
thingHandler.device.nodes.put(node.nodeID, node);
thingHandler.connection = connection;
thingHandler.handleCommand(property.channelUID, RefreshType.REFRESH);
verify(callback).stateUpdated(argThat(arg -> property.channelUID.equals(arg)), argThat(arg -> property.getChannelState().getCache().getChannelState().equals(arg)));
}
use of io.envoyproxy.envoy.config.core.v3.Node in project smarthome by eclipse.
the class ChildMapTests method createNode.
private Node createNode(String id) {
Node node = new Node(deviceTopic, id, ThingChannelConstants.testHomieThing, callback, spy(new NodeAttributes()));
doReturn(future).when(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(node.attributes).unsubscribe();
return node;
}
use of io.envoyproxy.envoy.config.core.v3.Node in project GeoGig by boundlessgeo.
the class CreateOSMChangesetOp method _call.
/**
* Executes the diff operation.
*
* @return an iterator to a set of differences between the two trees
* @see DiffEntry
*/
@Override
protected Iterator<ChangeContainer> _call() {
Iterator<DiffEntry> nodeIterator = command(DiffOp.class).setFilter(OSMUtils.NODE_TYPE_NAME).setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
Iterator<DiffEntry> wayIterator = command(DiffOp.class).setFilter(OSMUtils.WAY_TYPE_NAME).setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
Iterator<DiffEntry> iterator = Iterators.concat(nodeIterator, wayIterator);
final EntityConverter converter = new EntityConverter();
Function<DiffEntry, ChangeContainer> function = new Function<DiffEntry, ChangeContainer>() {
@Override
@Nullable
public ChangeContainer apply(@Nullable DiffEntry diff) {
NodeRef ref = diff.changeType().equals(ChangeType.REMOVED) ? diff.getOldObject() : diff.getNewObject();
RevFeature revFeature = command(RevObjectParse.class).setObjectId(ref.objectId()).call(RevFeature.class).get();
RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(ref.getMetadataId()).call(RevFeatureType.class).get();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
ImmutableList<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
ImmutableList<Optional<Object>> values = revFeature.getValues();
for (int i = 0; i < descriptors.size(); i++) {
PropertyDescriptor descriptor = descriptors.get(i);
Optional<Object> value = values.get(i);
featureBuilder.set(descriptor.getName(), value.orNull());
}
SimpleFeature feature = featureBuilder.buildFeature(ref.name());
Entity entity = converter.toEntity(feature, id);
EntityContainer container;
if (entity instanceof Node) {
container = new NodeContainer((Node) entity);
} else {
container = new WayContainer((Way) entity);
}
ChangeAction action = diff.changeType().equals(ChangeType.ADDED) ? ChangeAction.Create : diff.changeType().equals(ChangeType.MODIFIED) ? ChangeAction.Modify : ChangeAction.Delete;
return new ChangeContainer(container, action);
}
};
return Iterators.transform(iterator, function);
}
Aggregations