Search in sources :

Example 21 with Configuration

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

the class EngineRule method apply.

@Override
public Statement apply(Statement base, Description description) {
    Class<?> testClass = description.getTestClass();
    final String testMethod = description.getMethodName().replaceAll("\\[.*\\]", "");
    try {
        Configure[] configures = testClass.getDeclaredMethod(testMethod).getAnnotationsByType(Configure.class);
        Arrays.stream(configures).forEach(p -> properties.setProperty(p.name(), p.value()));
        Configuration config = description.getAnnotation(Configuration.class);
        if (config != null) {
            if (configurationRoot != null) {
                String resourceName = String.format("%s/%s", configurationRoot, config.value());
                configURL = testClass.getClassLoader().getResource(resourceName);
            } else {
                String resourceName = String.format("%s-%s", testClass.getSimpleName(), config.value());
                configURL = testClass.getResource(resourceName);
            }
        }
        cleanup();
    } catch (Exception e) {
        LangUtil.rethrowUnchecked(e);
    }
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            EngineConfiguration config = configuration();
            final Thread baseThread = Thread.currentThread();
            final List<Throwable> errors = new ArrayList<>();
            final ErrorHandler errorHandler = ex -> {
                errors.add(ex);
                baseThread.interrupt();
            };
            engine = builder.config(config).configURL(configURL).errorHandler(errorHandler).build();
            try {
                engine.start().get();
                base.evaluate();
            } catch (Throwable t) {
                errors.add(t);
            } finally {
                try {
                    engine.close();
                } catch (Throwable t) {
                    errors.add(t);
                } finally {
                    assertEmpty(errors);
                }
            }
        }
    };
}
Also used : ENGINE_DRAIN_ON_CLOSE(io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_DRAIN_ON_CLOSE) EngineBuilder(io.aklivity.zilla.runtime.engine.EngineBuilder) ENGINE_STREAMS_BUFFER_CAPACITY(io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_STREAMS_BUFFER_CAPACITY) ENGINE_WORKERS(io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_WORKERS) Statement(org.junit.runners.model.Statement) Arrays(java.util.Arrays) ErrorHandler(org.agrona.ErrorHandler) PropertyDef(io.aklivity.zilla.runtime.engine.Configuration.PropertyDef) Configure(io.aklivity.zilla.runtime.engine.test.annotation.Configure) TestRule(org.junit.rules.TestRule) URL(java.net.URL) Engine(io.aklivity.zilla.runtime.engine.Engine) EngineConfiguration(io.aklivity.zilla.runtime.engine.EngineConfiguration) ArrayList(java.util.ArrayList) ENGINE_SYNTHETIC_ABORT(io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_SYNTHETIC_ABORT) Objects.requireNonNull(java.util.Objects.requireNonNull) MultipleFailureException.assertEmpty(org.junit.runners.model.MultipleFailureException.assertEmpty) LangUtil(org.agrona.LangUtil) EngineStats(io.aklivity.zilla.runtime.engine.EngineStats) Path(java.nio.file.Path) ENGINE_RESPONSE_BUFFER_CAPACITY(io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_RESPONSE_BUFFER_CAPACITY) ENGINE_ROUTED_DELAY_MILLIS(io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_ROUTED_DELAY_MILLIS) ENGINE_COMMAND_BUFFER_CAPACITY(io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_COMMAND_BUFFER_CAPACITY) Properties(java.util.Properties) Files(java.nio.file.Files) Binding(io.aklivity.zilla.runtime.engine.binding.Binding) FOLLOW_LINKS(java.nio.file.FileVisitOption.FOLLOW_LINKS) IOException(java.io.IOException) Description(org.junit.runner.Description) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) ENGINE_COUNTERS_BUFFER_CAPACITY(io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_COUNTERS_BUFFER_CAPACITY) File(java.io.File) List(java.util.List) Files.exists(java.nio.file.Files.exists) Pattern(java.util.regex.Pattern) ENGINE_DIRECTORY(io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_DIRECTORY) ErrorHandler(org.agrona.ErrorHandler) EngineConfiguration(io.aklivity.zilla.runtime.engine.EngineConfiguration) Configuration(io.aklivity.zilla.runtime.engine.test.annotation.Configuration) Statement(org.junit.runners.model.Statement) ArrayList(java.util.ArrayList) IOException(java.io.IOException) EngineConfiguration(io.aklivity.zilla.runtime.engine.EngineConfiguration) Configure(io.aklivity.zilla.runtime.engine.test.annotation.Configure)

Example 22 with Configuration

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

the class ServerPartialWriteIT method shouldWriteWhenMoreDataArrivesWhileAwaitingSocketWritable.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.data.multiple.frames/server", "${client}/server.sent.data.multiple.frames/client" })
public void shouldWriteWhenMoreDataArrivesWhileAwaitingSocketWritable() throws Exception {
    // processData will be called for each of the two data frames. Make the first
    // 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 : 0)));
    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)

Example 23 with Configuration

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

the class ServerPartialWriteLimitsIT method shouldResetStreamsExceedingPartialWriteStreamsLimit.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.data.multiple.streams.second.was.reset/server" })
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));
    k3po.start();
    try (SocketChannel channel1 = SocketChannel.open();
        SocketChannel channel2 = SocketChannel.open()) {
        channel1.connect(new InetSocketAddress("127.0.0.1", 8080));
        channel2.connect(new InetSocketAddress("127.0.0.1", 8080));
        k3po.awaitBarrier("SECOND_STREAM_RESET_RECEIVED");
        resetReceived.set(true);
        ByteBuffer buf = ByteBuffer.allocate(256);
        while (buf.position() < 13) {
            int len = channel1.read(buf);
            if (len == -1) {
                break;
            }
        }
        buf.flip();
        assertEquals("server data 1", UTF_8.decode(buf).toString());
        int len = 0;
        buf.rewind();
        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) 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 24 with Configuration

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

the class ServerResetAndAbortIT method shouldShutdownOutputAndInputWhenServerSendsResetAndEnd.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.reset.and.end/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 shouldShutdownOutputAndInputWhenServerSendsResetAndEnd() 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 25 with Configuration

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

the class ServerResetAndAbortIT method shouldShutdownOutputWhenServerSendsAbort.

@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.abort/server" })
public void shouldShutdownOutputWhenServerSendsAbort() throws Exception {
    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);
    } finally {
        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)

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