Search in sources :

Example 6 with Configuration

use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.

the class ServerIT method shouldReceiveServerSentDataAndEnd.

@Test
@Configuration("server.json")
@Specification({ "${app}/server.sent.data.then.end/server" // No support for "read closed" in k3po tcp
})
public void shouldReceiveServerSentDataAndEnd() throws Exception {
    k3po.start();
    try (SocketChannel channel = SocketChannel.open()) {
        channel.connect(new InetSocketAddress("127.0.0.1", 8080));
        ByteBuffer buf = ByteBuffer.allocate(256);
        channel.read(buf);
        buf.flip();
        assertEquals("server data", UTF_8.decode(buf).toString());
        buf.rewind();
        int len = channel.read(buf);
        assertEquals(-1, len);
        k3po.finish();
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) ByteBuffer(java.nio.ByteBuffer) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 7 with Configuration

use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.

the class ServerIT method shouldReceiveClientSentDataAndEnd.

@Test
@Configuration("server.json")
@Specification({ "${app}/client.sent.data.then.end/server" // No support for "write close" in k3po tcp
})
public void shouldReceiveClientSentDataAndEnd() throws Exception {
    k3po.start();
    try (SocketChannel channel = SocketChannel.open()) {
        channel.connect(new InetSocketAddress("127.0.0.1", 8080));
        channel.write(UTF_8.encode("client data"));
        channel.shutdownOutput();
        k3po.finish();
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 8 with Configuration

use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.

the class ServerIT method shouldReceiveDataAfterSendingEnd.

@Test
@Configuration("server.json")
@Specification({ "${app}/server.sent.end.then.received.data/server" // No support for "read closed" in k3po tcp
})
public void shouldReceiveDataAfterSendingEnd() throws Exception {
    k3po.start();
    try (SocketChannel channel = SocketChannel.open()) {
        channel.connect(new InetSocketAddress("127.0.0.1", 8080));
        ByteBuffer buf = ByteBuffer.allocate(256);
        int len = channel.read(buf);
        buf.flip();
        assertEquals(-1, len);
        channel.write(UTF_8.encode("client data"));
        k3po.finish();
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) ByteBuffer(java.nio.ByteBuffer) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 9 with Configuration

use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.

the class ServerPartialWriteIT method shouldHandleEndOfStreamWithPendingWrite.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.data.then.end/server" })
public void shouldHandleEndOfStreamWithPendingWrite() throws Exception {
    AtomicBoolean endWritten = new AtomicBoolean(false);
    OnDataHelper.fragmentWrites(concat(of(5), generate(() -> 0)));
    HandleWriteHelper.fragmentWrites(generate(() -> endWritten.get() ? ALL : 0));
    k3po.start();
    try (SocketChannel channel = SocketChannel.open()) {
        channel.connect(new InetSocketAddress("127.0.0.1", 8080));
        k3po.awaitBarrier("END_WRITTEN");
        endWritten.set(true);
        ByteBuffer buf = ByteBuffer.allocate("server data".length() + 10);
        boolean closed = false;
        do {
            int len = channel.read(buf);
            if (len == -1) {
                closed = true;
                break;
            }
        } while (buf.position() < "server data".length());
        buf.flip();
        assertEquals("server data", UTF_8.decode(buf).toString());
        if (!closed) {
            buf.rewind();
            closed = channel.read(buf) == -1;
        }
        assertTrue("Stream was not closed", closed);
        k3po.finish();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) ByteBuffer(java.nio.ByteBuffer) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 10 with Configuration

use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.

the class ServerPartialWriteIT method shouldPartiallyWriteWhenMoreDataArrivesWhileAwaitingSocketWritable.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.data.multiple.frames/server", "${client}/server.sent.data.multiple.frames/client" })
public void shouldPartiallyWriteWhenMoreDataArrivesWhileAwaitingSocketWritable() throws Exception {
    // processData will be called for each of the two data frames. Make the first and second
    // each do a partial write, then write nothing until handleWrite is called after the
    // second processData call, when we write everything.
    AtomicBoolean finishWrite = new AtomicBoolean(false);
    OnDataHelper.fragmentWrites(concat(of(5), generate(() -> finishWrite.getAndSet(true) ? 0 : 15)));
    HandleWriteHelper.fragmentWrites(generate(() -> finishWrite.get() ? ALL : 0));
    k3po.finish();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Aggregations

Configuration (io.aklivity.zilla.runtime.engine.test.annotation.Configuration)44 Test (org.junit.Test)43 Specification (org.kaazing.k3po.junit.annotation.Specification)43 InetSocketAddress (java.net.InetSocketAddress)32 SocketChannel (java.nio.channels.SocketChannel)32 ByteBuffer (java.nio.ByteBuffer)19 ServerSocketChannel (java.nio.channels.ServerSocketChannel)15 BMRule (org.jboss.byteman.contrib.bmunit.BMRule)8 EngineStats (io.aklivity.zilla.runtime.engine.EngineStats)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 IOException (java.io.IOException)4 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)2 PropertyDef (io.aklivity.zilla.runtime.engine.Configuration.PropertyDef)1 Engine (io.aklivity.zilla.runtime.engine.Engine)1 EngineBuilder (io.aklivity.zilla.runtime.engine.EngineBuilder)1 EngineConfiguration (io.aklivity.zilla.runtime.engine.EngineConfiguration)1 ENGINE_COMMAND_BUFFER_CAPACITY (io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_COMMAND_BUFFER_CAPACITY)1 ENGINE_COUNTERS_BUFFER_CAPACITY (io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_COUNTERS_BUFFER_CAPACITY)1 ENGINE_DIRECTORY (io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_DIRECTORY)1