Search in sources :

Example 6 with Node

use of org.flyte.api.v1.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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConcurrentLinkedDeque8(org.jsr166.ConcurrentLinkedDeque8) Node(org.jsr166.ConcurrentLinkedDeque8.Node) Nullable(org.jetbrains.annotations.Nullable) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with Node

use of org.flyte.api.v1.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));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ChannelState(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState) PropertyAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Node(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node) NodeAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Property(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 8 with Node

use of org.flyte.api.v1.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)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Channel(org.eclipse.smarthome.core.thing.Channel) ArgumentMatchers(org.mockito.ArgumentMatchers) ScheduledFuture(java.util.concurrent.ScheduledFuture) ChannelState(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState) Command(org.eclipse.smarthome.core.types.Command) MockitoAnnotations(org.mockito.MockitoAnnotations) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) AbstractMqttAttributeClass(org.eclipse.smarthome.binding.mqtt.generic.internal.mapping.AbstractMqttAttributeClass) Thing(org.eclipse.smarthome.core.thing.Thing) StringType(org.eclipse.smarthome.core.library.types.StringType) MqttBindingConstants(org.eclipse.smarthome.binding.mqtt.generic.internal.MqttBindingConstants) Device(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Device) MqttChannelTypeProvider(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.MqttChannelTypeProvider) Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelStateHelper(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelStateHelper) DeviceAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.DeviceAttributes) ReadyState(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.DeviceAttributes.ReadyState) MqttBrokerConnection(org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection) RefreshType(org.eclipse.smarthome.core.types.RefreshType) List(java.util.List) NonNull(org.eclipse.jdt.annotation.NonNull) ChildMap(org.eclipse.smarthome.binding.mqtt.generic.internal.tools.ChildMap) ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) Mock(org.mockito.Mock) TypeParser(org.eclipse.smarthome.core.types.TypeParser) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) AbstractBrokerHandler(org.eclipse.smarthome.binding.mqtt.handler.AbstractBrokerHandler) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ChannelKind(org.eclipse.smarthome.core.thing.type.ChannelKind) NodeAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ThingChannelConstants.testHomieThing(org.eclipse.smarthome.binding.mqtt.generic.internal.handler.ThingChannelConstants.testHomieThing) Before(org.junit.Before) ThingHandlerCallback(org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback) Value(org.eclipse.smarthome.binding.mqtt.generic.internal.values.Value) DelayedBatchProcessing(org.eclipse.smarthome.binding.mqtt.generic.internal.tools.DelayedBatchProcessing) Property(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Test(org.junit.Test) SubscribeFieldToMQTTtopic(org.eclipse.smarthome.binding.mqtt.generic.internal.mapping.SubscribeFieldToMQTTtopic) Field(java.lang.reflect.Field) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PropertyAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes) Mockito(org.mockito.Mockito) Node(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node) ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ThingStatusDetail(org.eclipse.smarthome.core.thing.ThingStatusDetail) DataTypeEnum(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes.DataTypeEnum) Assert(org.junit.Assert) PropertyAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes) Node(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node) NodeAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes) Property(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property) Test(org.junit.Test)

Example 9 with Node

use of org.flyte.api.v1.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;
}
Also used : Node(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node) NodeAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes)

Example 10 with Node

use of org.flyte.api.v1.Node in project JavaData by SaitoAsuk-a.

the class FirstLastLinkList method delete.

/**
 * ɾ������������������������ɾ��
 */
public Node delete(long value) {
    Node current = first;
    Node previous = first;
    while (current.data != value) {
        if (current.next == null) {
            return null;
        }
        previous = current;
        current = current.next;
    }
    if (current == first) {
        first = first.next;
    } else {
        previous.next = current.next;
    }
    return current;
}
Also used : Node(dataStructure.JunkCourse.ch04.Node)

Aggregations

Test (org.junit.jupiter.api.Test)20 Node (org.flyte.api.v1.Node)15 TaskNode (org.flyte.api.v1.TaskNode)11 WorkflowTemplate (org.flyte.api.v1.WorkflowTemplate)11 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)9 Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Node (org.openhab.binding.mqtt.homie.internal.homie300.Node)9 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)9 List (java.util.List)7 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)7 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)7 NodeAttributes (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes)6 BranchNode (org.flyte.api.v1.BranchNode)6 WorkflowNode (org.flyte.api.v1.WorkflowNode)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 NodeAttributes (org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes)6 Map (java.util.Map)5 Property (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property)5 Node (dataStructure.JunkCourse.ch04.Node)4