diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java |
Publish
Diffstat (limited to 'jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java')
-rw-r--r-- | jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java b/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java new file mode 100644 index 00000000000..7f2e073e4d8 --- /dev/null +++ b/jrt/tests/com/yahoo/jrt/MandatoryMethodsTest.java @@ -0,0 +1,97 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.jrt; + + +import java.util.HashSet; + + +public class MandatoryMethodsTest extends junit.framework.TestCase { + + Supervisor server; + Acceptor acceptor; + Supervisor client; + Target target; + + public MandatoryMethodsTest(String name) { + super(name); + } + + public void setUp() throws ListenFailedException { + server = new Supervisor(new Transport()); + client = new Supervisor(new Transport()); + acceptor = server.listen(new Spec(Test.PORT)); + target = client.connect(new Spec("localhost", Test.PORT)); + } + + public void tearDown() { + target.close(); + acceptor.shutdown().join(); + client.transport().shutdown().join(); + server.transport().shutdown().join(); + } + + public void testPing() { + + Request req = new Request("frt.rpc.ping"); + target.invokeSync(req, 5.0); + + assertFalse(req.isError()); + assertEquals(0, req.returnValues().size()); + } + + public void testGetMethodList() { + + Request req = new Request("frt.rpc.getMethodList"); + target.invokeSync(req, 5.0); + + assertFalse(req.isError()); + assertTrue(req.checkReturnTypes("SSS")); + String[] names = req.returnValues().get(0).asStringArray(); + String[] param = req.returnValues().get(1).asStringArray(); + String[] ret = req.returnValues().get(2).asStringArray(); + assertEquals(3, names.length); + assertTrue(names.length == param.length); + assertTrue(names.length == ret.length); + HashSet<String> foundSet = new HashSet<String>(); + for (int i = 0; i < names.length; i++) { + if (names[i].equals("frt.rpc.ping")) { + assertEquals("", param[i]); + assertEquals("", ret[i]); + } else if (names[i].equals("frt.rpc.getMethodList")) { + assertEquals("", param[i]); + assertEquals("SSS", ret[i]); + } else if (names[i].equals("frt.rpc.getMethodInfo")) { + assertEquals("s", param[i]); + assertEquals("sssSSSS", ret[i]); + } + foundSet.add(names[i]); + } + assertEquals(3, foundSet.size()); + assertTrue(foundSet.contains("frt.rpc.ping")); + assertTrue(foundSet.contains("frt.rpc.getMethodList")); + assertTrue(foundSet.contains("frt.rpc.getMethodInfo")); + } + + public void testGetMethodInfo() { + Request req = new Request("frt.rpc.getMethodInfo"); + req.parameters().add(new StringValue("frt.rpc.getMethodInfo")); + target.invokeSync(req, 5.0); + + assertFalse(req.isError()); + assertTrue(req.checkReturnTypes("sssSSSS")); + + String desc = req.returnValues().get(0).asString(); + String param = req.returnValues().get(1).asString(); + String ret = req.returnValues().get(2).asString(); + String[] paramName = req.returnValues().get(3).asStringArray(); + String[] paramDesc = req.returnValues().get(4).asStringArray(); + String[] retName = req.returnValues().get(5).asStringArray(); + String[] retDesc = req.returnValues().get(6).asStringArray(); + assertEquals("s", param); + assertEquals("sssSSSS", ret); + assertEquals(1, paramName.length); + assertTrue(paramName.length == paramDesc.length); + assertEquals(7, retName.length); + assertTrue(retName.length == retDesc.length); + } +} |