Package javaflow.components.api

Examples of javaflow.components.api.Packet


        formatter = new PacketFormatter();
    }

    @Test
    public void contentAndIdIsIncluded(){
        Packet p = createPacket(1123l, "content abcd1234");
        when(p.getType()).thenReturn(Packet.PacketType.NORMAL);
        String result = formatter.format(p);
        Assert.assertTrue(result.contains("#1123: content abcd1234"),result);
    }
View Full Code Here


    private Packet createPacket() {
        return createPacket(1,"content");
    }
    private Packet createPacket(long id, Object content) {
        Packet packet = mock(Packet.class);
        when(packet.getId()).thenReturn(id);
        when(packet.getType()).thenReturn(Packet.PacketType.NORMAL);
        when(packet.getContent()).thenReturn(content);
        return packet;
    }
View Full Code Here


    @Test
    public void messageTypeIsIncluded(){
        PacketFormatter formatter = new PacketFormatter();
        Packet startPacket = createPacket();
        Packet endPacket = createPacket();
        beStart(startPacket);
        beEnd(endPacket);
        String startResult = formatter.format(startPacket);
        String endResult = formatter.format(endPacket);
        Assert.assertTrue(startResult.contains("START"),startResult);
View Full Code Here


    @Test
    public void messageMetadataIsIncluded(){
        PacketFormatter formatter = new PacketFormatter();
        Packet p = createPacket();
        when(p.getMetadataKeys()).thenReturn(Arrays.asList("a","b"));
        when(p.getMetadata("a")).thenReturn("1");
        when(p.getMetadata("b")).thenReturn(2);
        when(p.getType()).thenReturn(Packet.PacketType.NORMAL);
        String result = formatter.format(p);
        Assert.assertTrue(result.contains("{a:1, b:2}"),result);
    }
View Full Code Here

    }

    @Test
    public void chainIsIncluded(){
        List<Packet<?>> chain = new ArrayList<>();
        Packet p = createPacket();
        Packet c1 = createPacket();
        chain.add(c1);

        when(c1.getId()).thenReturn(12l);
        when(c1.getContent()).thenReturn("content");

        when(p.getId()).thenReturn(3l);
        when(p.getContent()).thenReturn("abcd");
        when(p.getType()).thenReturn(Packet.PacketType.NORMAL);
View Full Code Here

    @Test
    public void t() {
        OutputPorts ports = mock(OutputPorts.class);
        OutputPort port1 = mock(OutputPort.class);
        OutputPort port2 = mock(OutputPort.class);
        Packet packet1 = mock(Packet.class);
        Packet packet2 = mock(Packet.class);
        Packet packet3 = mock(Packet.class);
        Packet packet4 = mock(Packet.class);

        when(ports.size()).thenReturn(2);
        when(ports.port(0)).thenReturn(port1);
        when(ports.port(1)).thenReturn(port2);
        Iterator<OutputPort> outs = new OutputPortRoundRobinIterator(ports);
View Full Code Here

    InputPort in;
    OutputPort error;

    @Override
    public void execute() {
        Packet p = in.receive();
        if (p == null) {
            // This should never happend because component should not be started without
            // having an actual packet in one of its input ports.
            error.createPacket("NOOO, IT WAS NULL.").send();
        } else {
            p.drop();

        }
    }
View Full Code Here

        packet.attach(p1);
        packet.attach(p2);
        packet.attach(p3);
        Iterator<Packet> iterator = packet.iterator();
        Assert.assertTrue(iterator.hasNext());
        Packet p;
        p = iterator.next();
        Assert.assertEquals(p,p1);
        p1.detach();
        Assert.assertTrue(iterator.hasNext());
        Assert.assertEquals(p,p2);
View Full Code Here

    OutputPort out;

    @Override
    public void execute() {
        try {
            Packet packet = in.receive();
            packet.drop();
            out.createPacket("testing").send();
            out.send(packet);
            // Expect exception to be thrown from sending dropped packet
            out.createPacket("failed").send();
        } catch (Throwable e) {
View Full Code Here

    OutputPort result;

    @Override
    public void execute() {

        Packet packet = in.receive();
        result.createPacket("testing").send();
        try {
            out.send(packet);
            // Expect exception to be thrown from sending dropped packet
            result.createPacket("failed").send();
        } catch (PortIsClosed e) {
            packet.drop();
            result.createPacket("success").send();
        }
    }
View Full Code Here

TOP

Related Classes of javaflow.components.api.Packet

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.