Package javaflow.components.api

Examples of javaflow.components.api.InputPort


    }

    @Override
    public InputPort<T> next() {
        InputPort port;
        int count = 0;
        while ((port = ports.port(nextIndex())).isClosed() && count < ports.size()) {
            count++;
        };
        if (port.isClosed()) {
            return ports.port(0);
        }
        return port;

    }
View Full Code Here


public class InputPortRoundRobinIteratorTest {

    @Test
    public void iteratorRunsPortsInRoundRobinStyle() {
        InputPorts ports = mock(InputPorts.class);
        InputPort port1 = mock(InputPort.class);
        InputPort port2 = mock(InputPort.class);
        when(ports.size()).thenReturn(2);
        when(ports.port(0)).thenReturn(port1);
        when(ports.port(1)).thenReturn(port2);
        when(port1.isClosed()).thenReturn(false);
        when(port2.isClosed()).thenReturn(false);

        Iterator<InputPort> outs = new InputPortRoundRobinIterator(ports);
        Assert.assertTrue(outs.hasNext());
        outs.next().receive();
        Assert.assertTrue(outs.hasNext());
View Full Code Here

    }

    @Test
    public void iteratorSkipsClosedPorts() {
        InputPorts ports = mock(InputPorts.class);
        InputPort port1 = mock(InputPort.class, "port #1");
        InputPort port2 = mock(InputPort.class, "port #2");
        InputPort port3 = mock(InputPort.class, "port #3");
        when(ports.size()).thenReturn(3);
        when(ports.port(0)).thenReturn(port1);
        when(ports.port(1)).thenReturn(port2);
        when(ports.port(2)).thenReturn(port3);

        when(port1.isClosed()).thenReturn(false);
        when(port2.isClosed()).thenReturn(true);
        when(port3.isClosed()).thenReturn(false);



        Iterator<InputPort> outs = new InputPortRoundRobinIterator(ports);
        Assert.assertTrue(outs.hasNext());
View Full Code Here

    }

    @Test
    public void hasNoNextIfAllPortsAreClosed() {
        InputPorts ports = mock(InputPorts.class);
        InputPort port1 = mock(InputPort.class, "port #1");
        InputPort port2 = mock(InputPort.class, "port #2");
        when(ports.size()).thenReturn(2);
        when(ports.port(0)).thenReturn(port1);
        when(ports.port(1)).thenReturn(port2);

        when(port1.isClosed()).thenReturn(true);
        when(port2.isClosed()).thenReturn(true);

        Iterator<InputPort> outs = new InputPortRoundRobinIterator(ports);
        Assert.assertFalse(outs.hasNext());
    }
View Full Code Here

    }

    @Test
    public void nextWillReturnFirstPortIfAllAreClosed() {
        InputPorts ports = mock(InputPorts.class);
        InputPort port1 = mock(InputPort.class, "port #1");
        InputPort port2 = mock(InputPort.class, "port #2");
        when(ports.size()).thenReturn(2);
        when(ports.port(0)).thenReturn(port1);
        when(ports.port(1)).thenReturn(port2);

        when(port1.isClosed()).thenReturn(true);
        when(port2.isClosed()).thenReturn(true);

        Iterator<InputPort> outs = new InputPortRoundRobinIterator(ports);
        Assert.assertEquals(outs.next(), port1);
        Assert.assertEquals(outs.next(), port1);
    }
View Full Code Here

TOP

Related Classes of javaflow.components.api.InputPort

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.