Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
attilakreiner committed May 2, 2024
1 parent 0ab31e7 commit 79d1ecb
Show file tree
Hide file tree
Showing 10 changed files with 2,680 additions and 352 deletions.
6 changes: 6 additions & 0 deletions incubator/command-dump/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.aklivity.zilla</groupId>
<artifactId>binding-grpc</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.aklivity.zilla</groupId>
<artifactId>binding-grpc.spec</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DumpCommandRunner
{
private static final Path ENGINE_PATH = Path.of("target/zilla-itests");

private ZillaDumpCommand command;
private final ZillaDumpCommand command;

public DumpCommandRunner()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2021-2023 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.command.dump.internal.airline;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.testcontainers.containers.Container;

public final class DumpRule implements TestRule
{
private static final Matcher TIMESTAMP_MATCHER = Pattern.compile("Timestamp: 0x[0-9A-Fa-f]+").matcher("");
private static final String TIMESTAMP_PLACEHOLDER = "Timestamp: [timestamp]";

private static final Path ENGINE_PATH = Path.of("target/zilla-itests");
private static final Path PCAP_PATH = ENGINE_PATH.resolve("actual.pcap");
private static final Path TXT_PATH = ENGINE_PATH.resolve("actual.txt");
private static final DumpCommandRunner DUMP = new DumpCommandRunner();
private static final TsharkRunner TSHARK = new TsharkRunner();

private Path expected;

@Override
public Statement apply(
Statement base,
Description description)
{
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
base.evaluate();
DUMP.createPcap(PCAP_PATH);
Container.ExecResult result = TSHARK.createTxt(PCAP_PATH);
String result0 = replaceTimestamps(result.getStdout());
Files.writeString(TXT_PATH, result0);
assertThat(result.getExitCode(), equalTo(0));
assert expected != null;
assertThat(result0, equalTo(Files.readString(expected)));
}
};
}

public void expect(
String file) throws Exception
{
this.expected = resourceToPath(file);
}

private String replaceTimestamps(
String input)
{
TIMESTAMP_MATCHER.reset(input);
return TIMESTAMP_MATCHER.replaceAll(TIMESTAMP_PLACEHOLDER);
}

private static Path resourceToPath(
String name) throws Exception
{
URL resource = DumpRule.class.getResource(name);
assert resource != null;
return Path.of(resource.toURI());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2021-2023 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.command.dump.internal.airline;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.rules.RuleChain.outerRule;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.DisableOnDebug;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.kaazing.k3po.junit.annotation.Specification;
import org.kaazing.k3po.junit.rules.K3poRule;

import io.aklivity.zilla.runtime.engine.test.EngineRule;
import io.aklivity.zilla.runtime.engine.test.annotation.Configuration;

public class GrpcServerStreamRpcIT
{
private final K3poRule k3po = new K3poRule()
.addScriptRoot("net", "io/aklivity/zilla/specs/binding/grpc/streams/network/server.stream.rpc")
.addScriptRoot("app", "io/aklivity/zilla/specs/binding/grpc/streams/application/server.stream.rpc");

private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS));

private final EngineRule engine = new EngineRule()
.directory("target/zilla-itests")
.countersBufferCapacity(4096)
.configurationRoot("io/aklivity/zilla/specs/binding/grpc/config")
.external("app0")
.clean();

private final DumpRule dump = new DumpRule();

@Rule
public final TestRule chain = outerRule(dump).around(engine).around(k3po).around(timeout);

@Test
@Configuration("server.when.yaml")
@Specification({
"${net}/message.exchange/client",
"${app}/message.exchange/server"
})
public void shouldEstablishServerStreamRpc() throws Exception
{
k3po.finish();
dump.expect("expected_grpc_server_stream_rpc_establish.txt");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.rules.RuleChain.outerRule;

import java.net.URL;
import java.nio.file.Path;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.DisableOnDebug;
Expand All @@ -32,29 +29,26 @@
import io.aklivity.zilla.runtime.engine.test.EngineRule;
import io.aklivity.zilla.runtime.engine.test.annotation.Configuration;

public class HttpAuthorizationIT
public class Http1AuthorizationIT
{
private static final Path ENGINE_PATH = Path.of("target/zilla-itests");

private final K3poRule k3po = new K3poRule()
.addScriptRoot("net", "io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization")
.addScriptRoot("app", "io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/authorization");

private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS));

private final EngineRule engine = new EngineRule()
.directory(ENGINE_PATH.toString())
.directory("target/zilla-itests")
.countersBufferCapacity(8192)
.configure(HTTP_SERVER_HEADER, "Zilla")
.configurationRoot("io/aklivity/zilla/specs/binding/http/config/v1.1")
.external("app0")
.clean();

private final HelloRule hello = new HelloRule();
private final DumpRule dump = new DumpRule();

@Rule
//public final TestRule chain = outerRule(engine).around(k3po).around(timeout);
public final TestRule chain = outerRule(hello).around(engine).around(k3po).around(timeout);
public final TestRule chain = outerRule(dump).around(engine).around(k3po).around(timeout);

@Test
@Configuration("server.authorization.credentials.yaml")
Expand All @@ -64,17 +58,7 @@ public class HttpAuthorizationIT
})
public void shouldChallengeCredentialsHeader() throws Exception
{
System.out.println("----> 001");
k3po.finish();
System.out.println("----> 002");
hello.expect(resourceToPath("expected_http_authorization.txt"));
}

private static Path resourceToPath(
String name) throws Exception
{
URL resource = HttpAuthorizationIT.class.getResource(name);
assert resource != null;
return Path.of(resource.toURI());
dump.expect("expected_http1_authorization_challenge_credentials_header.txt");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2021-2023 Aklivity Inc
*
* Licensed under the Aklivity Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://www.aklivity.io/aklivity-community-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.command.dump.internal.airline;

import static io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration.HTTP_CONCURRENT_STREAMS;
import static io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration.HTTP_SERVER_HEADER;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.rules.RuleChain.outerRule;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.DisableOnDebug;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.kaazing.k3po.junit.annotation.Specification;
import org.kaazing.k3po.junit.rules.K3poRule;

import io.aklivity.zilla.runtime.engine.test.EngineRule;
import io.aklivity.zilla.runtime.engine.test.annotation.Configuration;

public class Http2AuthorizationIT
{
private final K3poRule k3po = new K3poRule()
.addScriptRoot("net", "io/aklivity/zilla/specs/binding/http/streams/network/rfc7540/authorization")
.addScriptRoot("app", "io/aklivity/zilla/specs/binding/http/streams/application/rfc7540/authorization");

private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS));

private final EngineRule engine = new EngineRule()
.directory("target/zilla-itests")
.countersBufferCapacity(8192)
.configure(HTTP_CONCURRENT_STREAMS, 100)
.configure(HTTP_SERVER_HEADER, "Zilla")
.configurationRoot("io/aklivity/zilla/specs/binding/http/config/v2")
.external("app0")
.clean();

private final DumpRule dump = new DumpRule();

@Rule
public final TestRule chain = outerRule(dump).around(engine).around(k3po).around(timeout);

@Test
@Configuration("server.authorization.credentials.yaml")
@Specification({
"${net}/challenge.credentials.header/client",
"${app}/challenge.credentials.header/server",
})
public void shouldChallengeCredentialsHeader() throws Exception
{
k3po.finish();
dump.expect("expected_http2_authorization_challenge_credentials_header.txt");
}
}
Loading

0 comments on commit 79d1ecb

Please sign in to comment.