diff options
Diffstat (limited to 'jrt_test/src/tests/slobrok-api')
-rw-r--r-- | jrt_test/src/tests/slobrok-api/.gitignore | 4 | ||||
-rw-r--r-- | jrt_test/src/tests/slobrok-api/CMakeLists.txt | 1 | ||||
-rw-r--r-- | jrt_test/src/tests/slobrok-api/DESC | 2 | ||||
-rw-r--r-- | jrt_test/src/tests/slobrok-api/FILES | 2 | ||||
-rw-r--r-- | jrt_test/src/tests/slobrok-api/SlobrokAPITest.java | 223 | ||||
-rwxr-xr-x | jrt_test/src/tests/slobrok-api/dotest.sh | 14 | ||||
-rw-r--r-- | jrt_test/src/tests/slobrok-api/progdefs.sh | 2 |
7 files changed, 248 insertions, 0 deletions
diff --git a/jrt_test/src/tests/slobrok-api/.gitignore b/jrt_test/src/tests/slobrok-api/.gitignore new file mode 100644 index 00000000000..b4c0ce28732 --- /dev/null +++ b/jrt_test/src/tests/slobrok-api/.gitignore @@ -0,0 +1,4 @@ +*.class +.depend +Makefile +out.slobrok.1 diff --git a/jrt_test/src/tests/slobrok-api/CMakeLists.txt b/jrt_test/src/tests/slobrok-api/CMakeLists.txt new file mode 100644 index 00000000000..5c90dd5bfcc --- /dev/null +++ b/jrt_test/src/tests/slobrok-api/CMakeLists.txt @@ -0,0 +1 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. diff --git a/jrt_test/src/tests/slobrok-api/DESC b/jrt_test/src/tests/slobrok-api/DESC new file mode 100644 index 00000000000..b44753d7d10 --- /dev/null +++ b/jrt_test/src/tests/slobrok-api/DESC @@ -0,0 +1,2 @@ +Test java port of slobrok api classes. Currently only tests with a +single slobrok server. diff --git a/jrt_test/src/tests/slobrok-api/FILES b/jrt_test/src/tests/slobrok-api/FILES new file mode 100644 index 00000000000..cc18fdd7eb7 --- /dev/null +++ b/jrt_test/src/tests/slobrok-api/FILES @@ -0,0 +1,2 @@ +SlobrokAPITest.java +out.slobrok.1 diff --git a/jrt_test/src/tests/slobrok-api/SlobrokAPITest.java b/jrt_test/src/tests/slobrok-api/SlobrokAPITest.java new file mode 100644 index 00000000000..5fd88f27b80 --- /dev/null +++ b/jrt_test/src/tests/slobrok-api/SlobrokAPITest.java @@ -0,0 +1,223 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + + +import com.yahoo.jrt.*; +import com.yahoo.jrt.slobrok.api.*; +import java.util.Comparator; +import java.util.Arrays; +import java.util.ArrayList; + + +public class SlobrokAPITest { + + private static class SpecList extends ArrayList { + public SpecList add(String name, String spec) { + add(new Mirror.Entry(name, spec)); + return this; + } + } + + String[] slobroks; + SlobrokList slist = new SlobrokList(); + boolean error = false; + Supervisor server = new Supervisor(new Transport()); + Supervisor client = new Supervisor(new Transport()); + Acceptor acceptor = null; + Mirror mirror = null; + Register register = null; + String mySpec = null; + + public SlobrokAPITest(String slobrokSpec) throws ListenFailedException { + slobroks = new String[1]; + slobroks[0] = slobrokSpec; + slist.setup(slobroks); + acceptor = server.listen(new Spec(0)); + mirror = new Mirror(client, slist); + register = new Register(server, slist, + "localhost", acceptor.port()); + mySpec = new Spec("localhost", acceptor.port()).toString(); + } + + void shutdown() { + register.shutdown(); + mirror.shutdown(); + acceptor.shutdown(); + client.transport().shutdown(); + server.transport().shutdown(); + } + + void check(String pattern, ArrayList result) { + Comparator cmp = new Comparator() { + public int compare(Object a, Object b) { + Mirror.Entry x = (Mirror.Entry) a; + Mirror.Entry y = (Mirror.Entry) b; + return x.compareTo(y); + } + }; + Mirror.Entry[] expect + = (Mirror.Entry[]) result.toArray(new Mirror.Entry[result.size()]); + Arrays.sort(expect, cmp); + Mirror.Entry[] actual = new Mirror.Entry[0]; + for (int i = 0; i < 600; i++) { + actual = mirror.lookup(pattern); + Arrays.sort(actual, cmp); + if (Arrays.equals(actual, expect)) { + err("lookup successful for pattern: " + pattern); + return; + } + try { Thread.sleep(100); } catch (InterruptedException e) {} + } + error = true; + err("lookup failed for pattern: " + pattern); + err("actual values:"); + if (actual.length == 0) { + err(" { EMPTY }"); + } + for (int i = 0; i < actual.length; i++) { + err(" {" + actual[i].getName() + ", " + actual[i].getSpec() + "}"); + } + err("expected values:"); + if (expect.length == 0) { + err(" { EMPTY }"); + } + for (int i = 0; i < expect.length; i++) { + err(" {" + expect[i].getName() + ", " + expect[i].getSpec() + "}"); + } + } + + public void runTests() throws Exception { + try { + register.registerName("A/x/w"); + check("A/x/w", new SpecList().add("A/x/w", mySpec)); + check("*/*", new SpecList()); + check("*/*/*", new SpecList().add("A/x/w", mySpec)); + + register.registerName("B/x"); + check("B/x", new SpecList().add("B/x", mySpec)); + check("*/*", new SpecList().add("B/x", mySpec)); + check("*/*/*", new SpecList().add("A/x/w", mySpec)); + + register.registerName("C/x/z"); + check("C/x/z", new SpecList().add("C/x/z", mySpec)); + check("*/*", new SpecList().add("B/x", mySpec)); + check("*/*/*", new SpecList() + .add("A/x/w", mySpec) + .add("C/x/z", mySpec)); + + register.registerName("D/y/z"); + check("D/y/z", new SpecList().add("D/y/z", mySpec)); + check("*/*", new SpecList().add("B/x", mySpec)); + check("*/*/*", new SpecList() + .add("A/x/w", mySpec) + .add("C/x/z", mySpec) + .add("D/y/z", mySpec)); + + register.registerName("E/y"); + check("E/y", new SpecList().add("E/y", mySpec)); + check("*/*", new SpecList() + .add("B/x", mySpec) + .add("E/y", mySpec)); + check("*/*/*", new SpecList() + .add("A/x/w", mySpec) + .add("C/x/z", mySpec) + .add("D/y/z", mySpec)); + + register.registerName("F/y/w"); + check("F/y/w", new SpecList().add("F/y/w", mySpec)); + check("*/*", new SpecList() + .add("B/x", mySpec) + .add("E/y", mySpec)); + check("*/*/*", new SpecList() + .add("A/x/w", mySpec) + .add("C/x/z", mySpec) + .add("D/y/z", mySpec) + .add("F/y/w", mySpec)); + + check("*", new SpecList()); + + check("B/*", new SpecList() + .add("B/x", mySpec)); + + check("*/y", new SpecList() + .add("E/y", mySpec)); + + check("*/x/*", new SpecList() + .add("A/x/w", mySpec) + .add("C/x/z", mySpec)); + + check("*/*/z", new SpecList() + .add("C/x/z", mySpec) + .add("D/y/z", mySpec)); + + check("A/*/z", new SpecList()); + + check("A/*/w", new SpecList() + .add("A/x/w", mySpec)); + + register.unregisterName("E/y"); + register.unregisterName("C/x/z"); + register.unregisterName("F/y/w"); + check("*/*", new SpecList() + .add("B/x", mySpec)); + check("*/*/*", new SpecList() + .add("A/x/w", mySpec) + .add("D/y/z", mySpec)); + + register.registerName("E/y"); + register.registerName("C/x/z"); + register.registerName("F/y/w"); + check("*/*", new SpecList() + .add("B/x", mySpec) + .add("E/y", mySpec)); + check("*/*/*", new SpecList() + .add("A/x/w", mySpec) + .add("C/x/z", mySpec) + .add("D/y/z", mySpec) + .add("F/y/w", mySpec)); + + register.unregisterName("E/y"); + register.unregisterName("C/x/z"); + register.unregisterName("F/y/w"); + check("*/*", new SpecList() + .add("B/x", mySpec)); + check("*/*/*", new SpecList() + .add("A/x/w", mySpec) + .add("D/y/z", mySpec)); + + register.registerName("E/y"); + register.registerName("C/x/z"); + register.registerName("F/y/w"); + check("*/*", new SpecList() + .add("B/x", mySpec) + .add("E/y", mySpec)); + check("*/*/*", new SpecList() + .add("A/x/w", mySpec) + .add("C/x/z", mySpec) + .add("D/y/z", mySpec) + .add("F/y/w", mySpec)); + + if (error) { + throw new Exception("Test failed"); + } + } finally { + shutdown(); + } + } + + public static void main(String[] args) { + if (args.length != 1) { + err("usage: SlobrokAPITest slobrok-spec"); + System.exit(1); + } + try { + new SlobrokAPITest(args[0]).runTests(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + + public static void err(String msg) { + System.err.println(msg); + } +} diff --git a/jrt_test/src/tests/slobrok-api/dotest.sh b/jrt_test/src/tests/slobrok-api/dotest.sh new file mode 100755 index 00000000000..4a221e5830c --- /dev/null +++ b/jrt_test/src/tests/slobrok-api/dotest.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +. ../../binref/env.sh + +ret=true + +export PORT_8 +sh $BINREF/progctl.sh progdefs.sh start slobrok 1 +${BINREF}/runjava SlobrokAPITest tcp/localhost:${PORT_8} || ret=false +${BINREF}/sbcmd ${PORT_8} slobrok.system.stop +sh $BINREF/progctl.sh progdefs.sh stop slobrok 1 + +$ret diff --git a/jrt_test/src/tests/slobrok-api/progdefs.sh b/jrt_test/src/tests/slobrok-api/progdefs.sh new file mode 100644 index 00000000000..af694ab8ad4 --- /dev/null +++ b/jrt_test/src/tests/slobrok-api/progdefs.sh @@ -0,0 +1,2 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +prog slobrok 1 "-p $PORT_8" |