Search in sources :

Example 1 with Configuration

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

the class ClientStatsIT method shouldEchoPayloadLength10k.

@Test
@Configuration("client.json")
@Specification({ "${app}/echo.payload.length.10k/client", "${net}/echo.payload.length.10k/server" })
public void shouldEchoPayloadLength10k() throws Exception {
    k3po.finish();
    EngineStats stats = engine.stats("test", "app0");
    assertThat(stats.initialBytes(), equalTo(10240L));
    assertThat(stats.replyBytes(), equalTo(10240L));
}
Also used : EngineStats(io.aklivity.zilla.runtime.engine.EngineStats) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 2 with Configuration

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

the class ClientResetAndAbortIT method shouldShutdownInputWhenClientSendsReset.

@Test
@Configuration("client.host.json")
@Specification({ "${client}/client.sent.reset/client" })
@BMRule(name = "shutdownInput", targetClass = "^java.nio.channels.SocketChannel", targetMethod = "shutdownInput()", helper = "io.aklivity.zilla.runtime.binding.tcp.internal.SocketChannelHelper$CountDownHelper", condition = "callerEquals(\"TcpClientFactory$TcpClient.onAppReset\", true, 2)", action = "countDown()")
public void shouldShutdownInputWhenClientSendsReset() throws Exception {
    CountDownLatch shutdownInputCalled = new CountDownLatch(1);
    CountDownHelper.initialize(shutdownInputCalled);
    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()) {
            channel.configureBlocking(false);
            channel.write(ByteBuffer.wrap("some data".getBytes()));
            k3po.awaitBarrier("READ_ABORTED");
            shutdownInputCalled.await();
        } finally {
            k3po.finish();
        }
    }
}
Also used : ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) ServerSocketChannel(java.nio.channels.ServerSocketChannel) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 3 with Configuration

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

the class ServerIOExceptionFromWriteIT method shouldResetWhenDeferredWriteThrowsIOException.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.data.received.reset.and.abort/server" })
@BMRules(rules = { @BMRule(name = "onApplicationData", helper = "io.aklivity.zilla.runtime.binding.tcp.internal.SocketChannelHelper$OnDataHelper", targetClass = "^java.nio.channels.SocketChannel", targetMethod = "write(java.nio.ByteBuffer)", condition = "callerEquals(\"TcpServerFactory$TcpServer.onAppData\", true, 2)", action = "return doWrite($0, $1);"), @BMRule(name = "onNetworkWritable", targetClass = "^java.nio.channels.SocketChannel", targetMethod = "write(java.nio.ByteBuffer)", condition = "callerEquals(\"TcpServerFactory$TcpServer.onNetWritable\", true, 2)", action = "throw new IOException(\"Simulating an IOException from write\")") })
public void shouldResetWhenDeferredWriteThrowsIOException() throws Exception {
    OnDataHelper.fragmentWrites(generate(() -> 0));
    k3po.start();
    try (SocketChannel channel = SocketChannel.open()) {
        channel.connect(new InetSocketAddress("127.0.0.1", 8080));
        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) BMRules(org.jboss.byteman.contrib.bmunit.BMRules) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 4 with Configuration

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

the class ServerIT method shouldNotGetRepeatedIOExceptionsFromReaderStreamRead.

@Test
@Configuration("server.json")
@Specification({ "${app}/server.sent.data/server" })
public void shouldNotGetRepeatedIOExceptionsFromReaderStreamRead() throws Exception {
    k3po.start();
    try (Socket socket = new Socket("127.0.0.1", 8080)) {
        socket.shutdownInput();
        Thread.sleep(500);
    }
    k3po.finish();
}
Also used : Socket(java.net.Socket) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 5 with Configuration

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

the class ServerIT method shouldUnbindRebind.

@Test
@Configuration("server.json")
@Specification({ "${app}/max.connections/server" })
public void shouldUnbindRebind() throws Exception {
    k3po.start();
    SocketChannel channel1 = SocketChannel.open();
    channel1.connect(new InetSocketAddress("127.0.0.1", 8080));
    SocketChannel channel2 = SocketChannel.open();
    channel2.connect(new InetSocketAddress("127.0.0.1", 8080));
    SocketChannel channel3 = SocketChannel.open();
    channel3.connect(new InetSocketAddress("127.0.0.1", 8080));
    k3po.awaitBarrier("CONNECTION_ACCEPTED_1");
    k3po.awaitBarrier("CONNECTION_ACCEPTED_2");
    k3po.awaitBarrier("CONNECTION_ACCEPTED_3");
    EngineStats stats = engine.stats("test", "net0");
    assertEquals(3, stats.initialOpens());
    assertEquals(0, stats.initialCloses());
    assertEquals(3, stats.replyOpens());
    assertEquals(0, stats.replyCloses());
    SocketChannel channel4 = SocketChannel.open();
    try {
        channel4.connect(new InetSocketAddress("127.0.0.1", 8080));
        fail("4th connect shouldn't succeed as max.connections = 3");
    } catch (IOException ioe) {
    // expected
    }
    assertEquals(3, stats.initialOpens());
    assertEquals(0, stats.initialCloses());
    assertEquals(3, stats.replyOpens());
    assertEquals(0, stats.replyCloses());
    channel1.close();
    channel4.close();
    k3po.awaitBarrier("CLOSED");
    // sleep so that rebind happens
    Thread.sleep(200);
    assertEquals(3, stats.initialOpens());
    assertEquals(1, stats.initialCloses());
    assertEquals(3, stats.replyOpens());
    assertEquals(1, stats.replyCloses());
    SocketChannel channel5 = SocketChannel.open();
    channel5.connect(new InetSocketAddress("127.0.0.1", 8080));
    k3po.awaitBarrier("CONNECTION_ACCEPTED_4");
    assertEquals(4, stats.initialOpens());
    assertEquals(1, stats.initialCloses());
    assertEquals(4, stats.replyOpens());
    assertEquals(1, stats.replyCloses());
    channel2.close();
    channel3.close();
    channel5.close();
    Thread.sleep(500);
    assertEquals(4, stats.initialOpens());
    assertEquals(4, stats.initialCloses());
    assertEquals(4, stats.replyOpens());
    assertEquals(4, stats.replyCloses());
    k3po.finish();
}
Also used : SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) EngineStats(io.aklivity.zilla.runtime.engine.EngineStats) IOException(java.io.IOException) 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