From: Roger Meier Date: Sun, 6 Jan 2013 13:33:39 +0000 (+0100) Subject: THRIFT-1594 Java test clients should have a return codes that reflect whether it... X-Git-Tag: 0.9.1~206 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=8ebe0d917cbd64dcd341a5f5412a2872122a44df;p=common%2Fthrift.git THRIFT-1594 Java test clients should have a return codes that reflect whether it succeeds or not. Patch: Kamil Salas and Roger Meier --- diff --git a/lib/java/test/org/apache/thrift/server/ServerTestBase.java b/lib/java/test/org/apache/thrift/server/ServerTestBase.java old mode 100644 new mode 100755 index 08b57e23..209038be --- a/lib/java/test/org/apache/thrift/server/ServerTestBase.java +++ b/lib/java/test/org/apache/thrift/server/ServerTestBase.java @@ -234,7 +234,7 @@ public abstract class ServerTestBase extends TestCase { x.errorCode = 1001; x.message = arg; throw x; - } else if (arg.equals("ApplicationException")) { + } else if (arg.equals("TException")) { throw new TException(arg); } else { Xtruct result = new Xtruct(); diff --git a/lib/java/test/org/apache/thrift/test/TestClient.java b/lib/java/test/org/apache/thrift/test/TestClient.java index 45369ba2..a7d5544b 100644 --- a/lib/java/test/org/apache/thrift/test/TestClient.java +++ b/lib/java/test/org/apache/thrift/test/TestClient.java @@ -48,37 +48,38 @@ import java.util.ArrayList; */ public class TestClient { public static void main(String [] args) { - try { - String host = "localhost"; - int port = 9090; - String url = null; - int numTests = 1; - boolean framed = false; + String host = "localhost"; + int port = 9090; + String url = null; + int numTests = 1; + boolean framed = false; - int socketTimeout = 1000; + int socketTimeout = 1000; - try { - for (int i = 0; i < args.length; ++i) { - if (args[i].equals("-h")) { - String[] hostport = (args[++i]).split(":"); - host = hostport[0]; - port = Integer.valueOf(hostport[1]); - } else if (args[i].equals("-f") || args[i].equals("-framed")) { - framed = true; - } else if (args[i].equals("-u")) { - url = args[++i]; - } else if (args[i].equals("-n")) { - numTests = Integer.valueOf(args[++i]); - } else if (args[i].equals("-timeout")) { - socketTimeout = Integer.valueOf(args[++i]); - } + try { + for (int i = 0; i < args.length; ++i) { + if (args[i].equals("-h")) { + String[] hostport = (args[++i]).split(":"); + host = hostport[0]; + port = Integer.valueOf(hostport[1]); + } else if (args[i].equals("-f") || args[i].equals("-framed")) { + framed = true; + } else if (args[i].equals("-u")) { + url = args[++i]; + } else if (args[i].equals("-n")) { + numTests = Integer.valueOf(args[++i]); + } else if (args[i].equals("-timeout")) { + socketTimeout = Integer.valueOf(args[++i]); } - } catch (Exception x) { - x.printStackTrace(); } + } catch (Exception x) { + x.printStackTrace(); + System.exit(1); + } - TTransport transport; + TTransport transport = null; + try { if (url != null) { transport = new THttpClient(url); } else { @@ -89,28 +90,35 @@ public class TestClient { transport = new TFramedTransport(transport); } } + } catch (Exception x) { + x.printStackTrace(); + System.exit(1); + } - TBinaryProtocol binaryProtocol = - new TBinaryProtocol(transport); - ThriftTest.Client testClient = - new ThriftTest.Client(binaryProtocol); - Insanity insane = new Insanity(); - - long timeMin = 0; - long timeMax = 0; - long timeTot = 0; + TBinaryProtocol binaryProtocol = + new TBinaryProtocol(transport); + ThriftTest.Client testClient = + new ThriftTest.Client(binaryProtocol); + Insanity insane = new Insanity(); - for (int test = 0; test < numTests; ++test) { + long timeMin = 0; + long timeMax = 0; + long timeTot = 0; + int failCount = 0; + for (int test = 0; test < numTests; ++test) { + try { /** * CONNECT TEST */ System.out.println("Test #" + (test+1) + ", " + "connect " + host + ":" + port); + try { transport.open(); } catch (TTransportException ttx) { + ttx.printStackTrace(); System.out.println("Connect failed: " + ttx.getMessage()); - continue; + System.exit(1); } long start = System.nanoTime(); @@ -124,6 +132,7 @@ public class TestClient { System.out.print(" = void\n"); } catch (TApplicationException tax) { tax.printStackTrace(); + failCount++; } /** @@ -132,6 +141,10 @@ public class TestClient { System.out.print("testString(\"Test\")"); String s = testClient.testString("Test"); System.out.print(" = \"" + s + "\"\n"); + if (!s.equals("Test")) { + failCount++; + System.out.println("FAILURE\n"); + } /** * BYTE TEST @@ -139,6 +152,10 @@ public class TestClient { System.out.print("testByte(1)"); byte i8 = testClient.testByte((byte)1); System.out.print(" = " + i8 + "\n"); + if (i8 != 1) { + failCount++; + System.out.println("FAILURE\n"); + } /** * I32 TEST @@ -146,6 +163,10 @@ public class TestClient { System.out.print("testI32(-1)"); int i32 = testClient.testI32(-1); System.out.print(" = " + i32 + "\n"); + if (i32 != -1) { + failCount++; + System.out.println("FAILURE\n"); + } /** * I64 TEST @@ -153,13 +174,21 @@ public class TestClient { System.out.print("testI64(-34359738368)"); long i64 = testClient.testI64(-34359738368L); System.out.print(" = " + i64 + "\n"); + if (i64 != -34359738368L) { + failCount++; + System.out.println("FAILURE\n"); + } /** * DOUBLE TEST */ - System.out.print("testDouble(5.325098235)"); - double dub = testClient.testDouble(5.325098235); + System.out.print("testDouble(-5.325098235)"); + double dub = testClient.testDouble(-5.325098235); System.out.print(" = " + dub + "\n"); + if (Math.abs(dub - (-5.325098235)) > 0.001) { + failCount++; + System.out.println("FAILURE\n"); + } /** * STRUCT TEST @@ -171,7 +200,15 @@ public class TestClient { out.i32_thing = -3; out.i64_thing = -5; Xtruct in = testClient.testStruct(out); - System.out.print(" = {" + "\"" + in.string_thing + "\", " + in.byte_thing + ", " + in.i32_thing + ", " + in.i64_thing + "}\n"); + System.out.print(" = {" + "\"" + + in.string_thing + "\"," + + in.byte_thing + ", " + + in.i32_thing + ", " + + in.i64_thing + "}\n"); + if (!in.equals(out)) { + failCount++; + System.out.println("FAILURE\n"); + } /** * NESTED STRUCT TEST @@ -183,7 +220,16 @@ public class TestClient { out2.i32_thing = 5; Xtruct2 in2 = testClient.testNest(out2); in = in2.struct_thing; - System.out.print(" = {" + in2.byte_thing + ", {" + "\"" + in.string_thing + "\", " + in.byte_thing + ", " + in.i32_thing + ", " + in.i64_thing + "}, " + in2.i32_thing + "}\n"); + System.out.print(" = {" + in2.byte_thing + ", {" + "\"" + + in.string_thing + "\", " + + in.byte_thing + ", " + + in.i32_thing + ", " + + in.i64_thing + "}, " + + in2.i32_thing + "}\n"); + if (!in2.equals(out2)) { + failCount++; + System.out.println("FAILURE\n"); + } /** * MAP TEST @@ -215,6 +261,15 @@ public class TestClient { System.out.print(key + " => " + mapout.get(key)); } System.out.print("}\n"); + if (!mapout.equals(mapin)) { + failCount++; + System.out.println("FAILURE\n"); + } + + /** + * STRING MAP TEST + * missing + */ /** * SET TEST @@ -246,6 +301,10 @@ public class TestClient { System.out.print(elem); } System.out.print("}\n"); + if (!setout.equals(setin)) { + failCount++; + System.out.println("FAILURE\n"); + } /** * LIST TEST @@ -277,6 +336,10 @@ public class TestClient { System.out.print(elem); } System.out.print("}\n"); + if (!listout.equals(listin)) { + failCount++; + System.out.println("FAILURE\n"); + } /** * ENUM TEST @@ -284,22 +347,42 @@ public class TestClient { System.out.print("testEnum(ONE)"); Numberz ret = testClient.testEnum(Numberz.ONE); System.out.print(" = " + ret + "\n"); + if (ret != Numberz.ONE) { + failCount++; + System.out.println("FAILURE\n"); + } System.out.print("testEnum(TWO)"); ret = testClient.testEnum(Numberz.TWO); System.out.print(" = " + ret + "\n"); + if (ret != Numberz.TWO) { + failCount++; + System.out.println("FAILURE\n"); + } System.out.print("testEnum(THREE)"); ret = testClient.testEnum(Numberz.THREE); System.out.print(" = " + ret + "\n"); + if (ret != Numberz.THREE) { + failCount++; + System.out.println("FAILURE\n"); + } System.out.print("testEnum(FIVE)"); ret = testClient.testEnum(Numberz.FIVE); System.out.print(" = " + ret + "\n"); + if (ret != Numberz.FIVE) { + failCount++; + System.out.println("FAILURE\n"); + } System.out.print("testEnum(EIGHT)"); ret = testClient.testEnum(Numberz.EIGHT); System.out.print(" = " + ret + "\n"); + if (ret != Numberz.EIGHT) { + failCount++; + System.out.println("FAILURE\n"); + } /** * TYPEDEF TEST @@ -307,6 +390,10 @@ public class TestClient { System.out.print("testTypedef(309858235082523)"); long uid = testClient.testTypedef(309858235082523L); System.out.print(" = " + uid + "\n"); + if (uid != 309858235082523L) { + failCount++; + System.out.println("FAILURE\n"); + } /** * NESTED MAP TEST @@ -381,14 +468,16 @@ public class TestClient { System.out.print("testClient.testException(\"Xception\") =>"); testClient.testException("Xception"); System.out.print(" void\nFAILURE\n"); + failCount++; } catch(Xception e) { - System.out.printf(" {%u, \"%s\"}\n", e.errorCode, e.message); + System.out.printf(" {%d, \"%s\"}\n", e.errorCode, e.message); } try { System.out.print("testClient.testException(\"TException\") =>"); testClient.testException("TException"); System.out.print(" void\nFAILURE\n"); + failCount++; } catch(TException e) { System.out.printf(" {\"%s\"}\n", e.getMessage()); } @@ -399,6 +488,7 @@ public class TestClient { System.out.print(" void\n"); }catch(Exception e) { System.out.printf(" exception\nFAILURE\n"); + failCount++; } @@ -410,16 +500,18 @@ public class TestClient { System.out.printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); testClient.testMultiException("Xception", "test 1"); System.out.print(" result\nFAILURE\n"); + failCount++; } catch(Xception e) { - System.out.printf(" {%u, \"%s\"}\n", e.errorCode, e.message); + System.out.printf(" {%d, \"%s\"}\n", e.errorCode, e.message); } try { System.out.printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); testClient.testMultiException("Xception2", "test 2"); System.out.print(" result\nFAILURE\n"); + failCount++; } catch(Xception2 e) { - System.out.printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing); + System.out.printf(" {%d, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing); } try { @@ -429,6 +521,7 @@ public class TestClient { System.out.printf(" {{\"%s\"}}\n", result.string_thing); } catch(Exception e) { System.out.printf(" exception\nFAILURE\n"); + failCount++; } @@ -441,9 +534,10 @@ public class TestClient { testClient.testOneway(3); long onewayElapsedMillis = (System.nanoTime() - startOneway) / 1000000; if (onewayElapsedMillis > 200) { - throw new Exception("Oneway test failed: took " + + System.out.println("Oneway test failed: took " + Long.toString(onewayElapsedMillis) + "ms"); + failCount++; } else { System.out.println("Success - took " + Long.toString(onewayElapsedMillis) + @@ -465,22 +559,27 @@ public class TestClient { timeTot += tot; transport.close(); + } catch (Exception x) { + x.printStackTrace(); + failCount++; } + } - long timeAvg = timeTot / numTests; + long timeAvg = timeTot / numTests; - System.out.println("Min time: " + timeMin/1000 + "us"); - System.out.println("Max time: " + timeMax/1000 + "us"); - System.out.println("Avg time: " + timeAvg/1000 + "us"); + System.out.println("Min time: " + timeMin/1000 + "us"); + System.out.println("Max time: " + timeMax/1000 + "us"); + System.out.println("Avg time: " + timeAvg/1000 + "us"); + try { String json = (new TSerializer(new TSimpleJSONProtocol.Factory())).toString(insane); - System.out.println("\nFor good meausre here is some JSON:\n" + json); - - } catch (Exception x) { + } catch (TException x) { x.printStackTrace(); + System.exit(1); } - } + System.exit(failCount); + } } diff --git a/lib/js/test/test.js b/lib/js/test/test.js index c30287fd..99fcc41d 100755 --- a/lib/js/test/test.js +++ b/lib/js/test/test.js @@ -1,4 +1,4 @@ -/* +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -205,13 +205,12 @@ module("Exception"); } }); - test("unexpected Application Exception", function() { + test("TException", function() { expect(1); try{ - client.testException("ApplicationException"); + client.testException("TException"); } catch(e) { - ok(true); //@HACK: ignore faulty java server response for exceptions - //equal(e.message, "ApplicationException"); + ok(true); } }); diff --git a/test/test.sh b/test/test.sh index 6deb87df..4c76d90f 100755 --- a/test/test.sh +++ b/test/test.sh @@ -27,7 +27,6 @@ # THRIFT-819 add Enumeration for protocol, transport and server types BASEDIR=$(dirname $0) -echo $BASEDIR cd $BASEDIR print_header() { @@ -41,9 +40,10 @@ do_test () { client_exec=$4 server_exec=$5 server_startup_time=$6 + client_delay=$7 testname=${client_server}_${protocol}_${transport} - server_timeout=$((${server_startup_time}+10)) + server_timeout=$((${server_startup_time}+${client_delay})) printf "%-16s %-11s %-17s" ${client_server} ${protocol} ${transport} timeout $server_timeout $server_exec > log/${testname}_server.log 2>&1 & sleep $server_startup_time @@ -61,7 +61,7 @@ do_test () { echo "" print_header fi - sleep 10 + sleep ${client_delay} } echo "Apache Thrift - integration test suite" @@ -94,7 +94,7 @@ for proto in $protocols; do do_test "cpp-cpp" "${proto}" "${trans}-${sock}" \ "cpp/TestClient --protocol=${proto} --transport=${trans} ${extraparam}" \ "cpp/TestServer --protocol=${proto} --transport=${trans} ${extraparam}" \ - "10" + "10" "5" done; done; done; @@ -105,78 +105,78 @@ rm -f /tmp/ThriftTest.thrift do_test "py-py" "binary" "buffered-ip" \ "py/TestClient.py --proto=binary --port=9090 --host=localhost --genpydir=py/gen-py" \ "py/TestServer.py --proto=binary --port=9090 --genpydir=py/gen-py TSimpleServer" \ - "10" + "10" "10" do_test "py-py" "json" "buffered-ip" \ "py/TestClient.py --proto=json --port=9090 --host=localhost --genpydir=py/gen-py" \ "py/TestServer.py --proto=json --port=9090 --genpydir=py/gen-py TSimpleServer" \ - "10" + "10" "10" do_test "py-cpp" "binary" "buffered-ip" \ "py/TestClient.py --proto=binary --port=9090 --host=localhost --genpydir=py/gen-py" \ "cpp/TestServer" \ - "10" + "10" "10" do_test "py-cpp" "json" "buffered-ip" \ "py/TestClient.py --proto=json --port=9090 --host=localhost --genpydir=py/gen-py" \ "cpp/TestServer --protocol=json" \ - "10" + "10" "10" do_test "cpp-py" "binary" "buffered-ip" \ "cpp/TestClient --protocol=binary --port=9090" \ "py/TestServer.py --proto=binary --port=9090 --genpydir=py/gen-py TSimpleServer" \ - "10" + "10" "10" do_test "cpp-py" "json" "buffered-ip" \ "cpp/TestClient --protocol=json --port=9090" \ "py/TestServer.py --proto=json --port=9090 --genpydir=py/gen-py TSimpleServer" \ - "10" + "10" "10" do_test "py-java" "binary" "buffered-ip" \ "py/TestClient.py --proto=binary --port=9090 --host=localhost --genpydir=py/gen-py" \ "ant -f ../lib/java/build.xml testserver" \ - "120" + "120" "10" do_test "py-java" "json" "buffered-ip" \ "py/TestClient.py --proto=json --port=9090 --host=localhost --genpydir=py/gen-py" \ "ant -f ../lib/java/build.xml testserver" \ - "120" + "120" "10" do_test "java-py" "binary" "buffered-ip" \ "ant -f ../lib/java/build.xml testclient" \ "py/TestServer.py --proto=binary --port=9090 --genpydir=py/gen-py TSimpleServer" \ - "10" + "10" "35" do_test "java-java" "binary" "buffered-ip" \ "ant -f ../lib/java/build.xml testclient" \ "ant -f ../lib/java/build.xml testserver" \ - "120" + "120" "35" do_test "cpp-java" "binary" "buffered-ip" \ "cpp/TestClient" \ "ant -f ../lib/java/build.xml testserver" \ - "100" + "100" "10" do_test "cpp-java" "json" "buffered-ip" \ "cpp/TestClient" \ "ant -f ../lib/java/build.xml testserver" \ - "100" + "100" "10" do_test "js-java" "json " "http-ip" \ "" \ "ant -f ../lib/js/test/build.xml unittest" \ - "120" + "120" "10" do_test "java-cpp" "binary" "buffered-ip" \ "ant -f ../lib/java/build.xml testclient" \ "cpp/TestServer" \ - "10" + "10" "35" do_test "perl-cpp" "binary" "buffered-ip" \ "perl -I perl/gen-perl/ -I../lib/perl/lib/ perl/TestClient.pl" \ "cpp/TestServer" \ - "10" + "10" "10" do_test "php-cpp" "binary" "buffered-ip" \ "make -C php/ client" \ "cpp/TestServer" \ - "10" + "10" "10" do_test "nodejs-nodejs" "binary" "framed-ip" \ "make -C nodejs/ client" \ "make -C nodejs/ server" \ - "1" + "1" "10" do_test "nodejs-cpp" "binary" "framed-ip" \ "make -C nodejs/ client" \ "cpp/TestServer --transport=framed" \ - "1" + "1" "10" do_test "cpp-nodejs" "binary" "framed-ip" \ "cpp/TestClient --transport=framed" \ "make -C nodejs/ server" \ - "1" + "1" "10" cd -