Search in sources :

Example 16 with Configuration

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

the class ClientResetAndAbortIT method shouldShutdownOutputAndInputWhenClientSendsResetAndEnd.

@Test
@Configuration("client.host.json")
@Specification({ "${client}/client.sent.reset.and.end/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 shouldShutdownOutputAndInputWhenClientSendsResetAndEnd() 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()) {
            ByteBuffer buf = ByteBuffer.allocate(20);
            int len = channel.read(buf);
            assertEquals(-1, len);
            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) ByteBuffer(java.nio.ByteBuffer) 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 17 with Configuration

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

the class ServerPartialWriteLimitsIT method shouldWriteWhenMoreDataArrivesWhileAwaitingSocketWritableWithoutOverflowingSlot.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.data.multiple.frames/server", "${client}/server.sent.data.multiple.frames/client" })
public void shouldWriteWhenMoreDataArrivesWhileAwaitingSocketWritableWithoutOverflowingSlot() throws Exception {
    AtomicInteger dataFramesReceived = new AtomicInteger();
    OnDataHelper.fragmentWrites(generate(() -> dataFramesReceived.incrementAndGet() == 1 ? 5 : dataFramesReceived.get() == 2 ? 6 : ALL));
    HandleWriteHelper.fragmentWrites(generate(() -> dataFramesReceived.get() >= 2 ? ALL : 0));
    k3po.finish();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Test(org.junit.Test) Specification(org.kaazing.k3po.junit.annotation.Specification)

Example 18 with Configuration

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

the class ServerResetAndAbortIT method shouldShutdownInputWhenServerSendsReset.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.reset/server" })
@BMRule(name = "shutdownInput", targetClass = "^java.nio.channels.SocketChannel", targetMethod = "shutdownInput()", helper = "io.aklivity.zilla.runtime.binding.tcp.internal.SocketChannelHelper$CountDownHelper", condition = "callerEquals(\"TcpServerFactory$TcpServer.onAppReset\", true, 2)", action = "countDown()")
public void shouldShutdownInputWhenServerSendsReset() throws Exception {
    CountDownLatch shutdownInputCalled = new CountDownLatch(1);
    CountDownHelper.initialize(shutdownInputCalled);
    k3po.start();
    try (SocketChannel channel = SocketChannel.open()) {
        channel.connect(new InetSocketAddress("127.0.0.1", 8080));
        channel.configureBlocking(false);
        channel.write(ByteBuffer.wrap("some data".getBytes()));
        try {
            k3po.awaitBarrier("READ_ABORTED");
            shutdownInputCalled.await();
        } catch (IOException e) {
            throw e;
        }
    } finally {
        k3po.finish();
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) 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 19 with Configuration

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

the class ServerResetAndAbortIT method shouldShutdownOutputAndInputWhenServerSendsAbortAndReset.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.abort.and.reset/server" })
@BMRule(name = "shutdownInput", targetClass = "^java.nio.channels.SocketChannel", targetMethod = "shutdownInput()", helper = "io.aklivity.zilla.runtime.binding.tcp.internal.SocketChannelHelper$CountDownHelper", condition = "callerEquals(\"TcpServerFactory$TcpServer.onAppReset\", true, 2)", action = "countDown()")
public void shouldShutdownOutputAndInputWhenServerSendsAbortAndReset() throws Exception {
    CountDownLatch shutdownInputCalled = new CountDownLatch(1);
    CountDownHelper.initialize(shutdownInputCalled);
    k3po.start();
    try (SocketChannel channel = SocketChannel.open()) {
        channel.connect(new InetSocketAddress("127.0.0.1", 8080));
        ByteBuffer buf = ByteBuffer.allocate(20);
        int len = channel.read(buf);
        assertEquals(-1, len);
        shutdownInputCalled.await();
    } finally {
        k3po.finish();
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) ByteBuffer(java.nio.ByteBuffer) 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 20 with Configuration

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

the class ServerStatsIT method shouldSendAndReceiveData.

@Test
@Configuration("server.json")
@Specification({ "${server}/client.and.server.sent.data.multiple.frames/server", "${client}/client.and.server.sent.data.multiple.frames/client" })
public void shouldSendAndReceiveData() throws Exception {
    k3po.finish();
    EngineStats stats = engine.stats("test", "net0");
    assertThat(stats.initialOpens(), equalTo(1L));
    assertThat(stats.replyOpens(), equalTo(1L));
    assertThat(stats.initialBytes(), equalTo(26L));
    assertThat(stats.replyBytes(), equalTo(26L));
}
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)

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