Search in sources :

Example 11 with Configuration

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

the class ClientIOExceptionFromReadIT method shouldNotResetWhenProcessingEndAfterIOExceptionFromRead.

@Test
@Configuration("client.host.json")
@Specification({ "${client}/client.received.abort.sent.end/client" })
public void shouldNotResetWhenProcessingEndAfterIOExceptionFromRead() throws Exception {
    try (ServerSocketChannel server = ServerSocketChannel.open()) {
        server.setOption(SO_REUSEADDR, true);
        server.bind(new InetSocketAddress("127.0.0.1", 8080));
        k3po.start();
        try (SocketChannel channel = server.accept()) {
            k3po.awaitBarrier("CONNECTED");
            channel.setOption(StandardSocketOptions.SO_LINGER, 0);
            channel.close();
            k3po.finish();
        }
    }
}
Also used : ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) ServerSocketChannel(java.nio.channels.ServerSocketChannel) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 12 with Configuration

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

the class ClientIOExceptionFromReadIT method shouldReportIOExceptionFromReadAsAbortAndReset.

@Test
@Configuration("client.host.json")
@Specification({ "${client}/client.received.reset.and.abort/client" })
public void shouldReportIOExceptionFromReadAsAbortAndReset() throws Exception {
    try (ServerSocketChannel server = ServerSocketChannel.open()) {
        server.setOption(SO_REUSEADDR, true);
        server.bind(new InetSocketAddress("127.0.0.1", 8080));
        k3po.start();
        try (SocketChannel channel = server.accept()) {
            k3po.awaitBarrier("CONNECTED");
            channel.setOption(StandardSocketOptions.SO_LINGER, 0);
            channel.close();
            k3po.finish();
        }
    }
}
Also used : ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) ServerSocketChannel(java.nio.channels.ServerSocketChannel) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 13 with Configuration

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

the class ClientIOExceptionFromWriteIT method shouldAbortAndResetWhenDeferredWriteThrowsIOException.

@Test
@Configuration("client.host.json")
@Specification({ "${client}/client.sent.data.received.abort.and.reset/client" })
@BMRules(rules = { @BMRule(name = "onData", helper = "io.aklivity.zilla.runtime.binding.tcp.internal.SocketChannelHelper$OnDataHelper", targetClass = "^java.nio.channels.SocketChannel", targetMethod = "write(java.nio.ByteBuffer)", condition = "callerEquals(\"TcpClientFactory$TcpClient.onAppData\", true, 2)", action = "return doWrite($0, $1);"), @BMRule(name = "handleWrite", targetClass = "^java.nio.channels.SocketChannel", targetMethod = "write(java.nio.ByteBuffer)", condition = "callerEquals(\"TcpClientFactory$TcpClient.onNetWritable\", true, 2)", action = "throw new IOException(\"Simulating an IOException from write\")") })
public void shouldAbortAndResetWhenDeferredWriteThrowsIOException() throws Exception {
    OnDataHelper.fragmentWrites(generate(() -> 0));
    try (ServerSocketChannel server = ServerSocketChannel.open()) {
        server.setOption(SO_REUSEADDR, true);
        server.bind(new InetSocketAddress("127.0.0.1", 8080));
        k3po.start();
        try (SocketChannel channel = server.accept()) {
            k3po.finish();
        }
    }
}
Also used : ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) ServerSocketChannel(java.nio.channels.ServerSocketChannel) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 14 with Configuration

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

the class ClientIT method shouldWriteDataAfterReceivingEndOfRead.

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

Example 15 with Configuration

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

the class ClientPartialWriteLimitsIT method shouldResetStreamsExceedingPartialWriteStreamsLimit.

@Test
@Configuration("client.host.json")
@Specification({ "${client}/client.sent.data.multiple.streams.second.was.reset/client" })
public void shouldResetStreamsExceedingPartialWriteStreamsLimit() throws Exception {
    // avoid spin write for first stream write
    OnDataHelper.fragmentWrites(concat(of(1), generate(() -> 0)));
    AtomicBoolean resetReceived = new AtomicBoolean(false);
    HandleWriteHelper.fragmentWrites(generate(() -> resetReceived.get() ? ALL : 0));
    try (ServerSocketChannel server = ServerSocketChannel.open()) {
        server.setOption(SO_REUSEADDR, true);
        server.bind(new InetSocketAddress("127.0.0.1", 8080));
        k3po.start();
        try (SocketChannel channel1 = server.accept();
            SocketChannel channel2 = server.accept()) {
            k3po.awaitBarrier("CLIENT_TWO_RESET_RECEIVED");
            resetReceived.set(true);
            ByteBuffer buf = ByteBuffer.allocate(256);
            while (buf.position() < 13) {
                int len = channel1.read(buf);
                assert len != -1;
            }
            buf.flip();
            assertEquals("client data 1", UTF_8.decode(buf).toString());
            buf.rewind();
            int len = 0;
            while (buf.position() < 13) {
                len = channel2.read(buf);
                if (len == -1) {
                    break;
                }
            }
            buf.flip();
            assertEquals(0, buf.remaining());
            assertEquals(-1, len);
            k3po.finish();
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) ByteBuffer(java.nio.ByteBuffer) ServerSocketChannel(java.nio.channels.ServerSocketChannel) 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