diff options
-rwxr-xr-x | lib/java/test/org/apache/thrift/server/ServerTestBase.java | 24 | ||||
-rw-r--r-- | lib/java/test/org/apache/thrift/test/TestClient.java | 352 | ||||
-rwxr-xr-x | lib/js/test/test.js | 51 | ||||
-rwxr-xr-x | test/README.md | 4 | ||||
-rw-r--r-- | test/ThriftTest.thrift | 2 | ||||
-rw-r--r-- | test/c_glib/src/test_client.c | 26 | ||||
-rw-r--r-- | test/c_glib/src/thrift_test_handler.c | 55 | ||||
-rw-r--r-- | test/cpp/src/TestClient.cpp | 16 | ||||
-rw-r--r-- | test/cpp/src/TestServer.cpp | 24 | ||||
-rw-r--r-- | test/hs/Makefile.am | 2 | ||||
-rwxr-xr-x | test/hs/TestServer.hs | 2 | ||||
-rw-r--r-- | test/known_failures_Linux.json | 52 | ||||
-rwxr-xr-x | test/py/TestClient.py | 44 |
13 files changed, 376 insertions, 278 deletions
diff --git a/lib/java/test/org/apache/thrift/server/ServerTestBase.java b/lib/java/test/org/apache/thrift/server/ServerTestBase.java index b95779b77..bc1fb9631 100755 --- a/lib/java/test/org/apache/thrift/server/ServerTestBase.java +++ b/lib/java/test/org/apache/thrift/server/ServerTestBase.java @@ -193,31 +193,11 @@ public abstract class ServerTestBase extends TestCase { public Map<Long, Map<Numberz,Insanity>> testInsanity(Insanity argument) { System.out.print("testInsanity()\n"); - Xtruct hello = new Xtruct(); - hello.string_thing = "Hello2"; - hello.byte_thing = 2; - hello.i32_thing = 2; - hello.i64_thing = 2; - - Xtruct goodbye = new Xtruct(); - goodbye.string_thing = "Goodbye4"; - goodbye.byte_thing = (byte)4; - goodbye.i32_thing = 4; - goodbye.i64_thing = (long)4; - - Insanity crazy = new Insanity(); - crazy.userMap = new HashMap<Numberz, Long>(); - crazy.userMap.put(Numberz.EIGHT, (long)8); - crazy.userMap.put(Numberz.FIVE, (long)5); - crazy.xtructs = new ArrayList<Xtruct>(); - crazy.xtructs.add(goodbye); - crazy.xtructs.add(hello); - HashMap<Numberz,Insanity> first_map = new HashMap<Numberz, Insanity>(); HashMap<Numberz,Insanity> second_map = new HashMap<Numberz, Insanity>();; - first_map.put(Numberz.TWO, crazy); - first_map.put(Numberz.THREE, crazy); + first_map.put(Numberz.TWO, argument); + first_map.put(Numberz.THREE, argument); Insanity looney = new Insanity(); second_map.put(Numberz.SIX, looney); diff --git a/lib/java/test/org/apache/thrift/test/TestClient.java b/lib/java/test/org/apache/thrift/test/TestClient.java index b54461eff..aca19c424 100644 --- a/lib/java/test/org/apache/thrift/test/TestClient.java +++ b/lib/java/test/org/apache/thrift/test/TestClient.java @@ -39,6 +39,7 @@ import org.apache.thrift.protocol.TJSONProtocol; import org.apache.thrift.protocol.TCompactProtocol; import org.apache.thrift.protocol.TSimpleJSONProtocol; +import java.nio.ByteBuffer; import java.util.Map; import java.util.HashMap; import java.util.Set; @@ -53,6 +54,13 @@ import java.util.ArrayList; * */ public class TestClient { + + private static int ERR_BASETYPES = 1; + private static int ERR_STRUCTS = 2; + private static int ERR_CONTAINERS = 4; + private static int ERR_EXCEPTIONS = 8; + private static int ERR_UNKNOWN = 64; + public static void main(String [] args) { String host = "localhost"; int port = 9090; @@ -69,8 +77,8 @@ public class TestClient { host = args[i].split("=")[1]; host.trim(); } else if (args[i].startsWith("--port")) { - port = Integer.valueOf(args[i].split("=")[1]); - } else if (args[i].startsWith("--n") || + port = Integer.valueOf(args[i].split("=")[1]); + } else if (args[i].startsWith("--n") || args[i].startsWith("--testloops")){ numTests = Integer.valueOf(args[i].split("=")[1]); } else if (args[i].equals("--timeout")) { @@ -85,7 +93,7 @@ public class TestClient { ssl = true; } else if (args[i].equals("--help")) { System.out.println("Allowed options:"); - System.out.println(" --help\t\t\tProduce help message"); + System.out.println(" --help\t\t\tProduce help message"); System.out.println(" --host=arg (=" + host + ")\tHost to connect"); System.out.println(" --port=arg (=" + port + ")\tPort number to connect"); System.out.println(" --transport=arg (=" + transport_type + ")\n\t\t\t\tTransport: buffered, framed, fastframed, http"); @@ -97,7 +105,7 @@ public class TestClient { } } catch (Exception x) { System.err.println("Can not parse arguments! See --help"); - System.exit(1); + System.exit(ERR_UNKNOWN); } try { @@ -105,7 +113,7 @@ public class TestClient { } else if (protocol_type.equals("compact")) { } else if (protocol_type.equals("json")) { } else { - throw new Exception("Unknown protocol type! " + protocol_type); + throw new Exception("Unknown protocol type! " + protocol_type); } if (transport_type.equals("buffered")) { } else if (transport_type.equals("framed")) { @@ -119,7 +127,7 @@ public class TestClient { } } catch (Exception e) { System.err.println("Error: " + e.getMessage()); - System.exit(1); + System.exit(ERR_UNKNOWN); } TTransport transport = null; @@ -146,7 +154,7 @@ public class TestClient { } } catch (Exception x) { x.printStackTrace(); - System.exit(1); + System.exit(ERR_UNKNOWN); } TProtocol tProtocol = null; @@ -166,7 +174,7 @@ public class TestClient { long timeMax = 0; long timeTot = 0; - int failCount = 0; + int returnCode = 0; for (int test = 0; test < numTests; ++test) { try { /** @@ -180,7 +188,7 @@ public class TestClient { } catch (TTransportException ttx) { ttx.printStackTrace(); System.out.println("Connect failed: " + ttx.getMessage()); - System.exit(1); + System.exit(ERR_UNKNOWN); } } @@ -195,7 +203,7 @@ public class TestClient { System.out.print(" = void\n"); } catch (TApplicationException tax) { tax.printStackTrace(); - failCount++; + returnCode |= ERR_BASETYPES; } /** @@ -205,8 +213,8 @@ public class TestClient { String s = testClient.testString("Test"); System.out.print(" = \"" + s + "\"\n"); if (!s.equals("Test")) { - failCount++; - System.out.println("FAILURE\n"); + returnCode |= ERR_BASETYPES; + System.out.println("*** FAILURE ***\n"); } /** @@ -216,8 +224,8 @@ public class TestClient { byte i8 = testClient.testByte((byte)1); System.out.print(" = " + i8 + "\n"); if (i8 != 1) { - failCount++; - System.out.println("FAILURE\n"); + returnCode |= ERR_BASETYPES; + System.out.println("*** FAILURE ***\n"); } /** @@ -227,8 +235,8 @@ public class TestClient { int i32 = testClient.testI32(-1); System.out.print(" = " + i32 + "\n"); if (i32 != -1) { - failCount++; - System.out.println("FAILURE\n"); + returnCode |= ERR_BASETYPES; + System.out.println("*** FAILURE ***\n"); } /** @@ -238,8 +246,8 @@ public class TestClient { long i64 = testClient.testI64(-34359738368L); System.out.print(" = " + i64 + "\n"); if (i64 != -34359738368L) { - failCount++; - System.out.println("FAILURE\n"); + returnCode |= ERR_BASETYPES; + System.out.println("*** FAILURE ***\n"); } /** @@ -249,14 +257,40 @@ public class TestClient { 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"); + returnCode |= ERR_BASETYPES; + System.out.println("*** FAILURE ***\n"); } /** * BINARY TEST */ - System.out.print("TODO: testBinary( ... )"); + try { + System.out.print("testBinary(-128...127) = "); + byte[] data = new byte[] {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127}; + ByteBuffer bin = testClient.testBinary(ByteBuffer.wrap(data)); + bin.mark(); + byte[] bytes = new byte[bin.limit() - bin.position()]; + bin.get(bytes); + bin.reset(); + System.out.print("{"); + boolean first = true; + for (int i = 0; i < bytes.length; ++i) { + if (first) + first = false; + else + System.out.print(", "); + System.out.print(bytes[i]); + } + System.out.println("}"); + if (!ByteBuffer.wrap(data).equals(bin)) { + returnCode |= ERR_BASETYPES; + System.out.println("*** FAILURE ***\n"); + } + } catch (Exception ex) { + returnCode |= ERR_BASETYPES; + System.out.println("\n*** FAILURE ***\n"); + ex.printStackTrace(System.out); + } /** * STRUCT TEST @@ -268,14 +302,14 @@ 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 + ", " + + 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"); + returnCode |= ERR_STRUCTS; + System.out.println("*** FAILURE ***\n"); } /** @@ -288,15 +322,15 @@ 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 + "\", " + + 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"); + returnCode |= ERR_STRUCTS; + System.out.println("*** FAILURE ***\n"); } /** @@ -330,14 +364,48 @@ public class TestClient { } System.out.print("}\n"); if (!mapout.equals(mapin)) { - failCount++; - System.out.println("FAILURE\n"); + returnCode |= ERR_CONTAINERS; + System.out.println("*** FAILURE ***\n"); } /** * STRING MAP TEST - * missing */ + try { + Map<String, String> smapout = new HashMap<String, String>(); + smapout.put("a", "2"); + smapout.put("b", "blah"); + smapout.put("some", "thing"); + for (String key : smapout.keySet()) { + if (first) { + first = false; + } else { + System.out.print(", "); + } + System.out.print(key + " => " + smapout.get(key)); + } + System.out.print("})"); + Map<String, String> smapin = testClient.testStringMap(smapout); + System.out.print(" = {"); + first = true; + for (String key : smapin.keySet()) { + if (first) { + first = false; + } else { + System.out.print(", "); + } + System.out.print(key + " => " + smapout.get(key)); + } + System.out.print("}\n"); + if (!smapout.equals(smapin)) { + returnCode |= ERR_CONTAINERS; + System.out.println("*** FAILURE ***\n"); + } + } catch (Exception ex) { + returnCode |= ERR_CONTAINERS; + System.out.println("*** FAILURE ***\n"); + ex.printStackTrace(System.out); + } /** * SET TEST @@ -370,8 +438,8 @@ public class TestClient { } System.out.print("}\n"); if (!setout.equals(setin)) { - failCount++; - System.out.println("FAILURE\n"); + returnCode |= ERR_CONTAINERS; + System.out.println("*** FAILURE ***\n"); } /** @@ -405,8 +473,8 @@ public class TestClient { } System.out.print("}\n"); if (!listout.equals(listin)) { - failCount++; - System.out.println("FAILURE\n"); + returnCode |= ERR_CONTAINERS; + System.out.println("*** FAILURE ***\n"); } /** @@ -416,40 +484,40 @@ public class TestClient { Numberz ret = testClient.testEnum(Numberz.ONE); System.out.print(" = " + ret + "\n"); if (ret != Numberz.ONE) { - failCount++; - System.out.println("FAILURE\n"); + returnCode |= ERR_STRUCTS; + 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"); + returnCode |= ERR_STRUCTS; + 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"); + returnCode |= ERR_STRUCTS; + 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"); + returnCode |= ERR_STRUCTS; + 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"); + returnCode |= ERR_STRUCTS; + System.out.println("*** FAILURE ***\n"); } /** @@ -459,8 +527,8 @@ public class TestClient { long uid = testClient.testTypedef(309858235082523L); System.out.print(" = " + uid + "\n"); if (uid != 309858235082523L) { - failCount++; - System.out.println("FAILURE\n"); + returnCode |= ERR_BASETYPES; + System.out.println("*** FAILURE ***\n"); } /** @@ -479,121 +547,174 @@ public class TestClient { System.out.print("}, "); } System.out.print("}\n"); + if (mm.size() != 2 || !mm.containsKey(4) || !mm.containsKey(-4)) { + returnCode |= ERR_CONTAINERS; + System.out.println("*** FAILURE ***\n"); + } else { + Map<Integer, Integer> m1 = mm.get(4); + Map<Integer, Integer> m2 = mm.get(-4); + if (m1.get(1) != 1 || m1.get(2) != 2 || m1.get(3) != 3 || m1.get(4) != 4 || + m2.get(-1) != -1 || m2.get(-2) != -2 || m2.get(-3) != -3 || m2.get(-4) != -4) { + returnCode |= ERR_CONTAINERS; + System.out.println("*** FAILURE ***\n"); + } + } /** * INSANITY TEST */ - insane = new Insanity(); - insane.userMap = new HashMap<Numberz, Long>(); - insane.userMap.put(Numberz.FIVE, (long)5000); - Xtruct truck = new Xtruct(); - truck.string_thing = "Truck"; - truck.byte_thing = (byte)8; - truck.i32_thing = 8; - truck.i64_thing = 8; - insane.xtructs = new ArrayList<Xtruct>(); - insane.xtructs.add(truck); - System.out.print("testInsanity()"); - Map<Long,Map<Numberz,Insanity>> whoa = - testClient.testInsanity(insane); - System.out.print(" = {"); - for (long key : whoa.keySet()) { - Map<Numberz,Insanity> val = whoa.get(key); - System.out.print(key + " => {"); - for (Numberz k2 : val.keySet()) { - Insanity v2 = val.get(k2); - System.out.print(k2 + " => {"); - Map<Numberz, Long> userMap = v2.userMap; - System.out.print("{"); - if (userMap != null) { - for (Numberz k3 : userMap.keySet()) { - System.out.print(k3 + " => " + userMap.get(k3) + ", "); + boolean insanityFailed = true; + try { + Xtruct hello = new Xtruct(); + hello.string_thing = "Hello2"; + hello.byte_thing = 2; + hello.i32_thing = 2; + hello.i64_thing = 2; + + Xtruct goodbye = new Xtruct(); + goodbye.string_thing = "Goodbye4"; + goodbye.byte_thing = (byte)4; + goodbye.i32_thing = 4; + goodbye.i64_thing = (long)4; + + insane.userMap = new HashMap<Numberz, Long>(); + insane.userMap.put(Numberz.EIGHT, (long)8); + insane.userMap.put(Numberz.FIVE, (long)5); + insane.xtructs = new ArrayList<Xtruct>(); + insane.xtructs.add(goodbye); + insane.xtructs.add(hello); + + System.out.print("testInsanity()"); + Map<Long,Map<Numberz,Insanity>> whoa = + testClient.testInsanity(insane); + System.out.print(" = {"); + for (long key : whoa.keySet()) { + Map<Numberz,Insanity> val = whoa.get(key); + System.out.print(key + " => {"); + + for (Numberz k2 : val.keySet()) { + Insanity v2 = val.get(k2); + System.out.print(k2 + " => {"); + Map<Numberz, Long> userMap = v2.userMap; + System.out.print("{"); + if (userMap != null) { + for (Numberz k3 : userMap.keySet()) { + System.out.print(k3 + " => " + userMap.get(k3) + ", "); + } + } + System.out.print("}, "); + + List<Xtruct> xtructs = v2.xtructs; + System.out.print("{"); + if (xtructs != null) { + for (Xtruct x : xtructs) { + System.out.print("{" + "\"" + x.string_thing + "\", " + x.byte_thing + ", " + x.i32_thing + ", "+ x.i64_thing + "}, "); + } } + System.out.print("}"); + + System.out.print("}, "); } System.out.print("}, "); - - List<Xtruct> xtructs = v2.xtructs; - System.out.print("{"); - if (xtructs != null) { - for (Xtruct x : xtructs) { - System.out.print("{" + "\"" + x.string_thing + "\", " + x.byte_thing + ", " + x.i32_thing + ", "+ x.i64_thing + "}, "); + } + System.out.print("}\n"); + if (whoa.size() == 2 && whoa.containsKey(1L) && whoa.containsKey(2L)) { + Map<Numberz, Insanity> first_map = whoa.get(1L); + Map<Numberz, Insanity> second_map = whoa.get(2L); + if (first_map.size() == 2 && + first_map.containsKey(Numberz.TWO) && + first_map.containsKey(Numberz.THREE) && + second_map.size() == 1 && + second_map.containsKey(Numberz.SIX) && + insane.equals(first_map.get(Numberz.TWO)) && + insane.equals(first_map.get(Numberz.THREE))) { + Insanity six =second_map.get(Numberz.SIX); + // Cannot use "new Insanity().equals(six)" because as of now, struct/container + // fields with default requiredness have isset=false for local instances and yet + // received empty values from other languages like C++ have isset=true . + if (six.getUserMapSize() == 0 && six.getXtructsSize() == 0) { + // OK + insanityFailed = false; } } - System.out.print("}"); - - System.out.print("}, "); } - System.out.print("}, "); + } catch (Exception ex) { + returnCode |= ERR_STRUCTS; + System.out.println("*** FAILURE ***\n"); + ex.printStackTrace(System.out); + insanityFailed = false; + } + if (insanityFailed) { + returnCode |= ERR_STRUCTS; + System.out.println("*** FAILURE ***\n"); } - System.out.print("}\n"); - /** * EXECPTION TEST */ try { System.out.print("testClient.testException(\"Xception\") =>"); testClient.testException("Xception"); - System.out.print(" void\nFAILURE\n"); - failCount++; + System.out.print(" void\n*** FAILURE ***\n"); + returnCode |= ERR_EXCEPTIONS; } catch(Xception e) { 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++; + System.out.print(" void\n*** FAILURE ***\n"); + returnCode |= ERR_EXCEPTIONS; } catch(TException e) { System.out.printf(" {\"%s\"}\n", e.getMessage()); } - + try { System.out.print("testClient.testException(\"success\") =>"); testClient.testException("success"); System.out.print(" void\n"); }catch(Exception e) { - System.out.printf(" exception\nFAILURE\n"); - failCount++; + System.out.printf(" exception\n*** FAILURE ***\n"); + returnCode |= ERR_EXCEPTIONS; } - - + + /** * MULTI EXCEPTION TEST */ - + try { System.out.printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); testClient.testMultiException("Xception", "test 1"); - System.out.print(" result\nFAILURE\n"); - failCount++; + System.out.print(" result\n*** FAILURE ***\n"); + returnCode |= ERR_EXCEPTIONS; } catch(Xception e) { 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++; + System.out.print(" result\n*** FAILURE ***\n"); + returnCode |= ERR_EXCEPTIONS; } catch(Xception2 e) { System.out.printf(" {%d, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing); } - + try { System.out.print("testClient.testMultiException(\"success\", \"test 3\") =>"); Xtruct result; result = testClient.testMultiException("success", "test 3"); System.out.printf(" {{\"%s\"}}\n", result.string_thing); } catch(Exception e) { - System.out.printf(" exception\nFAILURE\n"); - failCount++; + System.out.printf(" exception\n*** FAILURE ***\n"); + returnCode |= ERR_EXCEPTIONS; } - + /** * ONEWAY TEST */ @@ -603,9 +724,10 @@ public class TestClient { long onewayElapsedMillis = (System.nanoTime() - startOneway) / 1000000; if (onewayElapsedMillis > 200) { System.out.println("Oneway test failed: took " + - Long.toString(onewayElapsedMillis) + - "ms"); - failCount++; + Long.toString(onewayElapsedMillis) + + "ms"); + System.out.printf("*** FAILURE ***\n"); + returnCode |= ERR_BASETYPES; } else { System.out.println("Success - took " + Long.toString(onewayElapsedMillis) + @@ -628,8 +750,9 @@ public class TestClient { transport.close(); } catch (Exception x) { + System.out.printf("*** FAILURE ***\n"); x.printStackTrace(); - failCount++; + returnCode |= ERR_UNKNOWN; } } @@ -641,13 +764,14 @@ public class TestClient { try { String json = (new TSerializer(new TSimpleJSONProtocol.Factory())).toString(insane); - System.out.println("\nFor good meausre here is some JSON:\n" + json); + System.out.println("\nSample TSimpleJSONProtocol output:\n" + json); } catch (TException x) { + System.out.println("*** FAILURE ***"); x.printStackTrace(); - System.exit(1); + returnCode |= ERR_BASETYPES; } - System.exit(failCount); + System.exit(returnCode); } } diff --git a/lib/js/test/test.js b/lib/js/test/test.js index ee146128a..0c7d2cb66 100755 --- a/lib/js/test/test.js +++ b/lib/js/test/test.js @@ -303,45 +303,30 @@ module("Exception"); module("Insanity"); + var crazy = { + "userMap":{ "5":5, "8":8 }, + "xtructs":[{ + "string_thing":"Goodbye4", + "byte_thing":4, + "i32_thing":4, + "i64_thing":4 + }, + { + "string_thing":"Hello2", + "byte_thing":2, + "i32_thing":2, + "i64_thing":2 + }] + }; test("testInsanity", function() { var insanity = { "1":{ - "2":{ - "userMap":{ "5":5, "8":8 }, - "xtructs":[{ - "string_thing":"Goodbye4", - "byte_thing":4, - "i32_thing":4, - "i64_thing":4 - }, - { - "string_thing":"Hello2", - "byte_thing":2, - "i32_thing":2, - "i64_thing":2 - } - ] - }, - "3":{ - "userMap":{ "5":5, "8":8 }, - "xtructs":[{ - "string_thing":"Goodbye4", - "byte_thing":4, - "i32_thing":4, - "i64_thing":4 - }, - { - "string_thing":"Hello2", - "byte_thing":2, - "i32_thing":2, - "i64_thing":2 - } - ] - } + "2":crazy, + "3":crazy }, "2":{ "6":{ "userMap":null, "xtructs":null } } }; - var res = client.testInsanity(new ThriftTest.Insanity()); + var res = client.testInsanity(new ThriftTest.Insanity(crazy)); ok(res, JSON.stringify(res)); ok(insanity, JSON.stringify(insanity)); diff --git a/test/README.md b/test/README.md index c1a73ec7b..066b34f65 100755 --- a/test/README.md +++ b/test/README.md @@ -161,7 +161,9 @@ failing tests: #define TEST_STRUCTS 2 // 0000 0010 #define TEST_CONTAINERS 4 // 0000 0100 #define TEST_EXCEPTIONS 8 // 0000 1000 - #define TEST_NOTUSED 240 // 1111 0000 (reserved bits) + #define TEST_UNKNOWN 64 // 0100 0000 (Failed to prepare environemt etc.) + #define TEST_TIMEOUT 128 // 1000 0000 + #define TEST_NOTUSED 48 // 0011 0000 (reserved bits) Tests that have not been executed at all count as errors. diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift index a74956610..8eef23cd7 100644 --- a/test/ThriftTest.thrift +++ b/test/ThriftTest.thrift @@ -292,7 +292,7 @@ service ThriftTest * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s' * @param string arg - a string indication what type of exception to throw * if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception" - * elsen if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and message = "This is an Xception2" + * elsen if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and struct_thing.string_thing = "This is an Xception2" * else do not throw anything * @return Xtruct - an Xtruct with string_thing = arg1 */ diff --git a/test/c_glib/src/test_client.c b/test/c_glib/src/test_client.c index b1fe0657c..fd429c80a 100644 --- a/test/c_glib/src/test_client.c +++ b/test/c_glib/src/test_client.c @@ -204,7 +204,7 @@ main (int argc, char **argv) gint byte_thing, i32_thing, inner_byte_thing, inner_i32_thing; gint64 i64_thing, inner_i64_thing; - TTestXtruct *xtruct_out, *xtruct_in, *inner_xtruct_in; + TTestXtruct *xtruct_out, *xtruct_out2, *xtruct_in, *inner_xtruct_in; TTestXtruct2 *xtruct2_out, *xtruct2_in; GHashTable *map_out, *map_in, *inner_map_in; @@ -217,8 +217,9 @@ main (int argc, char **argv) GArray *list_out, *list_in; TTestNumberz numberz; + TTestNumberz numberz2; - TTestUserId user_id, *user_id_ptr; + TTestUserId user_id, *user_id_ptr, *user_id_ptr2; TTestInsanity *insanity_out, *insanity_in; GHashTable *user_map; @@ -1021,17 +1022,28 @@ main (int argc, char **argv) NULL); numberz = T_TEST_NUMBERZ_FIVE; + numberz2 = T_TEST_NUMBERZ_EIGHT; user_id_ptr = g_malloc (sizeof *user_id_ptr); - *user_id_ptr = 5000; + *user_id_ptr = 5; + user_id_ptr2 = g_malloc (sizeof *user_id_ptr); + *user_id_ptr2 = 8; g_hash_table_insert (user_map, (gpointer)numberz, user_id_ptr); + g_hash_table_insert (user_map, (gpointer)numberz2, user_id_ptr2); g_hash_table_unref (user_map); xtruct_out = g_object_new (T_TEST_TYPE_XTRUCT, - "string_thing", "Truck", - "byte_thing", 8, - "i32_thing", 8, - "i64_thing", 8LL, + "string_thing", "Hello2", + "byte_thing", 2, + "i32_thing", 2, + "i64_thing", 2LL, NULL); + xtruct_out2 = g_object_new (T_TEST_TYPE_XTRUCT, + "string_thing", "Goodbye4", + "byte_thing", 4, + "i32_thing", 4, + "i64_thing", 4LL, + NULL); + g_ptr_array_add (xtructs, xtruct_out2); g_ptr_array_add (xtructs, xtruct_out); g_ptr_array_unref (xtructs); diff --git a/test/c_glib/src/thrift_test_handler.c b/test/c_glib/src/thrift_test_handler.c index d82befbe6..a9983b5e6 100644 --- a/test/c_glib/src/thrift_test_handler.c +++ b/test/c_glib/src/thrift_test_handler.c @@ -472,8 +472,6 @@ thrift_test_handler_test_insanity (TTestThriftTestIf *iface, const TTestInsanity *argument, GError **error) { - TTestXtruct *hello; - TTestXtruct *goodbye; TTestXtruct *xtruct_in; gchar *string_thing = NULL; @@ -483,7 +481,6 @@ thrift_test_handler_test_insanity (TTestThriftTestIf *iface, GPtrArray *xtructs; - TTestInsanity *crazy; TTestInsanity *looney; GHashTable *user_map; @@ -502,50 +499,10 @@ thrift_test_handler_test_insanity (TTestThriftTestIf *iface, guint i; THRIFT_UNUSED_VAR (iface); - THRIFT_UNUSED_VAR (argument); THRIFT_UNUSED_VAR (error); printf ("testInsanity()\n"); - hello = g_object_new (T_TEST_TYPE_XTRUCT, - "string_thing", "Hello2", - "byte_thing", 2, - "i32_thing", 2, - "i64_thing", 2, - NULL); - - goodbye = g_object_new (T_TEST_TYPE_XTRUCT, - "string_thing", "Goodbye4", - "byte_thing", 4, - "i32_thing", 4, - "i64_thing", 4, - NULL); - - crazy = g_object_new (T_TEST_TYPE_INSANITY, NULL); - g_object_get (crazy, - "userMap", &user_map, - "xtructs", &xtructs, - NULL); - - user_id = g_malloc(sizeof *user_id); - *user_id = 8; - g_hash_table_insert (user_map, - GINT_TO_POINTER (T_TEST_NUMBERZ_EIGHT), - user_id); - - g_ptr_array_add (xtructs, goodbye); - - user_id = g_malloc(sizeof *user_id); - *user_id = 5; - g_hash_table_insert (user_map, - GINT_TO_POINTER (T_TEST_NUMBERZ_FIVE), - user_id); - - g_ptr_array_add (xtructs, hello); - - g_hash_table_unref (user_map); - g_ptr_array_unref (xtructs); - first_map = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, @@ -557,17 +514,17 @@ thrift_test_handler_test_insanity (TTestThriftTestIf *iface, g_hash_table_insert (first_map, GINT_TO_POINTER (T_TEST_NUMBERZ_TWO), - crazy); + argument); g_hash_table_insert (first_map, GINT_TO_POINTER (T_TEST_NUMBERZ_THREE), - crazy); + argument); - /* Increment crazy's ref count since first_map now holds two + /* Increment argument's ref count since first_map now holds two references to it and would otherwise attempt to deallocate it twice during destruction. We do this instead of creating a copy - of crazy in order to mimic the C++ implementation (and since, - frankly, the world needs less crazy, not more). */ - g_object_ref (crazy); + of argument in order to mimic the C++ implementation (and since, + frankly, the world needs less argument, not more). */ + g_object_ref (argument); looney = g_object_new (T_TEST_TYPE_INSANITY, NULL); g_hash_table_insert (second_map, diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp index 7c425a97b..e70989948 100644 --- a/test/cpp/src/TestClient.cpp +++ b/test/cpp/src/TestClient.cpp @@ -107,6 +107,12 @@ static void testVoid_clientReturn(const char* host, } int main(int argc, char** argv) { + int ERR_BASETYPES = 1; + int ERR_STRUCTS = 2; + int ERR_CONTAINERS = 4; + int ERR_EXCEPTIONS = 8; + int ERR_UNKNOWN = 64; + string file_path = boost::filesystem::system_complete(argv[0]).string(); string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH); #if _WIN32 @@ -149,7 +155,7 @@ int main(int argc, char** argv) { if (vm.count("help")) { cout << desc << "\n"; - return 1; + return ERR_UNKNOWN; } try { @@ -175,7 +181,7 @@ int main(int argc, char** argv) { } catch (std::exception& e) { cerr << e.what() << endl; cout << desc << "\n"; - return 1; + return ERR_UNKNOWN; } if (vm.count("ssl")) { @@ -267,10 +273,6 @@ int main(int argc, char** argv) { uint64_t time_tot = 0; int return_code = 0; - int ERR_BASETYPES = 1; - int ERR_STRUCTS = 2; - int ERR_CONTAINERS = 4; - int ERR_EXCEPTIONS = 8; int test = 0; for (test = 0; test < numTests; ++test) { @@ -279,7 +281,7 @@ int main(int argc, char** argv) { transport->open(); } catch (TTransportException& ttx) { printf("Connect failed: %s\n", ttx.what()); - return 1; + return ERR_UNKNOWN; } /** diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp index e5bc31e93..66d3bb2f6 100644 --- a/test/cpp/src/TestServer.cpp +++ b/test/cpp/src/TestServer.cpp @@ -221,34 +221,14 @@ public: } void testInsanity(map<UserId, map<Numberz::type, Insanity> >& insane, const Insanity& argument) { - (void)argument; printf("testInsanity()\n"); - Xtruct hello; - hello.string_thing = "Hello2"; - hello.byte_thing = 2; - hello.i32_thing = 2; - hello.i64_thing = 2; - - Xtruct goodbye; - goodbye.string_thing = "Goodbye4"; - goodbye.byte_thing = 4; - goodbye.i32_thing = 4; - goodbye.i64_thing = 4; - - Insanity crazy; - crazy.userMap.insert(make_pair(Numberz::EIGHT, 8)); - crazy.xtructs.push_back(goodbye); - Insanity looney; - crazy.userMap.insert(make_pair(Numberz::FIVE, 5)); - crazy.xtructs.push_back(hello); - map<Numberz::type, Insanity> first_map; map<Numberz::type, Insanity> second_map; - first_map.insert(make_pair(Numberz::TWO, crazy)); - first_map.insert(make_pair(Numberz::THREE, crazy)); + first_map.insert(make_pair(Numberz::TWO, argument)); + first_map.insert(make_pair(Numberz::THREE, argument)); second_map.insert(make_pair(Numberz::SIX, looney)); diff --git a/test/hs/Makefile.am b/test/hs/Makefile.am index e171248f6..b41a3915f 100644 --- a/test/hs/Makefile.am +++ b/test/hs/Makefile.am @@ -39,3 +39,5 @@ clean-local: all-local: stubs ghc -igen-hs TestServer.hs ghc -igen-hs TestClient.hs + +precross: all-local diff --git a/test/hs/TestServer.hs b/test/hs/TestServer.hs index a880a5e9c..90ec11e78 100755 --- a/test/hs/TestServer.hs +++ b/test/hs/TestServer.hs @@ -235,7 +235,7 @@ instance ThriftTest_Iface TestHandler where System.IO.putStrLn $ "testMultiException(" ++ show s1 ++ ", " ++ show s2 ++ ")" case s1 of "Xception" -> throw $ Xception 1001 "This is an Xception" - "Xception2" -> throw $ Xception2 2002 default_Xtruct + "Xception2" -> throw $ Xception2 2002 $ Xtruct "This is an Xception2" 0 0 0 "TException" -> throw ThriftException _ -> return default_Xtruct{ xtruct_string_thing = s2 } diff --git a/test/known_failures_Linux.json b/test/known_failures_Linux.json index ee12ebfff..9c567517a 100644 --- a/test/known_failures_Linux.json +++ b/test/known_failures_Linux.json @@ -5,6 +5,9 @@ "c_glib-csharp_binary_framed-ip", "c_glib-hs_binary_buffered-ip", "c_glib-hs_binary_framed-ip", + "c_glib-java_binary_buffered-ip", + "c_glib-java_binary_framed-fastframed-ip", + "c_glib-java_binary_framed-ip", "c_glib-nodejs_binary_buffered-ip", "c_glib-nodejs_binary_framed-ip", "c_glib-py_binary-accel_buffered-ip", @@ -109,13 +112,21 @@ "csharp-nodejs_json_buffered-ip-ssl", "csharp-nodejs_json_framed-ip", "csharp-nodejs_json_framed-ip-ssl", + "csharp-py_binary-accel_buffered-ip", "csharp-py_binary-accel_buffered-ip-ssl", + "csharp-py_binary-accel_framed-ip", "csharp-py_binary-accel_framed-ip-ssl", + "csharp-py_binary_buffered-ip", "csharp-py_binary_buffered-ip-ssl", + "csharp-py_binary_framed-ip", "csharp-py_binary_framed-ip-ssl", + "csharp-py_compact_buffered-ip", "csharp-py_compact_buffered-ip-ssl", + "csharp-py_compact_framed-ip", "csharp-py_compact_framed-ip-ssl", + "csharp-py_json_buffered-ip", "csharp-py_json_buffered-ip-ssl", + "csharp-py_json_framed-ip", "csharp-py_json_framed-ip-ssl", "csharp-rb_binary-accel_buffered-ip", "csharp-rb_binary-accel_framed-ip", @@ -125,8 +136,6 @@ "csharp-rb_compact_framed-ip", "csharp-rb_json_buffered-ip", "csharp-rb_json_framed-ip", - "go-c_glib_binary_buffered-ip", - "go-c_glib_binary_framed-ip", "go-cpp_json_buffered-ip", "go-cpp_json_buffered-ip-ssl", "go-cpp_json_framed-ip", @@ -139,6 +148,12 @@ "go-csharp_json_framed-ip-ssl", "go-hs_json_buffered-ip", "go-hs_json_framed-ip", + "go-java_json_buffered-ip", + "go-java_json_buffered-ip-ssl", + "go-java_json_framed-fastframed-ip", + "go-java_json_framed-fastframed-ip-ssl", + "go-java_json_framed-ip", + "go-java_json_framed-ip-ssl", "go-nodejs_binary_buffered-ip", "go-nodejs_binary_buffered-ip-ssl", "go-nodejs_binary_framed-ip", @@ -161,12 +176,11 @@ "hs-csharp_compact_framed-ip", "hs-csharp_json_buffered-ip", "hs-csharp_json_framed-ip", - "hs-go_binary_buffered-ip", - "hs-go_binary_framed-ip", - "hs-go_compact_buffered-ip", - "hs-go_compact_framed-ip", "hs-go_json_buffered-ip", "hs-go_json_framed-ip", + "hs-java_json_buffered-ip", + "hs-java_json_framed-fastframed-ip", + "hs-java_json_framed-ip", "hs-nodejs_binary_buffered-ip", "hs-nodejs_binary_framed-ip", "hs-nodejs_compact_buffered-ip", @@ -194,8 +208,6 @@ "java-rb_json_buffered-ip", "java-rb_json_fastframed-framed-ip", "java-rb_json_framed-ip", - "nodejs-c_glib_binary_buffered-ip", - "nodejs-c_glib_binary_framed-ip", "nodejs-cpp_binary_buffered-ip", "nodejs-cpp_binary_buffered-ip-ssl", "nodejs-cpp_binary_framed-ip", @@ -226,7 +238,24 @@ "nodejs-hs_compact_framed-ip", "nodejs-hs_json_buffered-ip", "nodejs-hs_json_framed-ip", + "nodejs-java_binary_buffered-ip", + "nodejs-java_binary_buffered-ip-ssl", + "nodejs-java_binary_framed-fastframed-ip", + "nodejs-java_binary_framed-fastframed-ip-ssl", + "nodejs-java_binary_framed-ip", + "nodejs-java_binary_framed-ip-ssl", + "nodejs-java_compact_buffered-ip", + "nodejs-java_compact_buffered-ip-ssl", + "nodejs-java_compact_framed-fastframed-ip", + "nodejs-java_compact_framed-fastframed-ip-ssl", + "nodejs-java_compact_framed-ip", + "nodejs-java_compact_framed-ip-ssl", + "nodejs-java_json_buffered-ip", "nodejs-java_json_buffered-ip-ssl", + "nodejs-java_json_framed-fastframed-ip", + "nodejs-java_json_framed-fastframed-ip-ssl", + "nodejs-java_json_framed-ip", + "nodejs-java_json_framed-ip-ssl", "nodejs-py_binary-accel_buffered-ip", "nodejs-py_binary-accel_buffered-ip-ssl", "nodejs-py_binary-accel_framed-ip", @@ -278,16 +307,15 @@ "py-rb_compact_framed-ip", "py-rb_json_buffered-ip", "py-rb_json_framed-ip", - "rb-c_glib_accel-binary_buffered-ip", - "rb-c_glib_accel-binary_framed-ip", - "rb-c_glib_binary_buffered-ip", - "rb-c_glib_binary_framed-ip", "rb-cpp_json_buffered-ip", "rb-cpp_json_framed-ip", "rb-csharp_json_buffered-ip", "rb-csharp_json_framed-ip", "rb-hs_json_buffered-ip", "rb-hs_json_framed-ip", + "rb-java_json_buffered-ip", + "rb-java_json_framed-fastframed-ip", + "rb-java_json_framed-ip", "rb-nodejs_json_buffered-ip", "rb-nodejs_json_framed-ip", "rb-rb_json_buffered-ip", diff --git a/test/py/TestClient.py b/test/py/TestClient.py index 51111a661..7fe48f655 100755 --- a/test/py/TestClient.py +++ b/test/py/TestClient.py @@ -175,24 +175,27 @@ class AbstractTest(unittest.TestCase): self.assertEqual(y, x) def testEnum(self): + print('testEnum') x = Numberz.FIVE y = self.client.testEnum(x) self.assertEqual(y, x) def testTypedef(self): + print('testTypedef') x = 0xffffffffffffff # 7 bytes of 0xff y = self.client.testTypedef(x) self.assertEqual(y, x) + @unittest.skip('Cannot use dict as dict key') def testMapMap(self): + print('testMapMap') # does not work: dict() is not a hashable type, so a dict() cannot be used as a key in another dict() - #x = { {1:10, 2:20}, {1:100, 2:200, 3:300}, {1:1000, 2:2000, 3:3000, 4:4000} } - try: - y = self.client.testMapMap() - except: - pass + x = {{1: 10, 2: 20}, {1: 100, 2: 200, 3: 300}, {1: 1000, 2: 2000, 3: 3000, 4: 4000}} + y = self.client.testMapMap(x) + self.assertEqual(y, x) def testMulti(self): + print('testMulti') xpected = Xtruct(string_thing='Hello2', byte_thing=74, i32_thing=0xff00ff, i64_thing=0xffffffffd0d0) y = self.client.testMulti(xpected.byte_thing, xpected.i32_thing, @@ -203,11 +206,12 @@ class AbstractTest(unittest.TestCase): self.assertEqual(y, xpected) def testException(self): + print('testException') self.client.testException('Safe') try: self.client.testException('Xception') self.fail("should have gotten exception") - except Xception, x: + except Xception as x: self.assertEqual(x.errorCode, 1001) self.assertEqual(x.message, 'Xception') # TODO ensure same behavior for repr within generated python variants @@ -216,12 +220,33 @@ class AbstractTest(unittest.TestCase): #self.assertEqual(x_repr, 'Xception(errorCode=1001, message=\'Xception\')') try: - self.client.testException("throw_undeclared") - self.fail("should have thrown exception") - except Exception: # type is undefined + self.client.testException('TException') + self.fail("should have gotten exception") + except TException as x: pass + # Should not throw + self.client.testException('success') + + def testMultiException(self): + print('testMultiException') + try: + self.client.testMultiException('Xception', 'ignore') + except Xception as ex: + self.assertEqual(ex.errorCode, 1001) + self.assertEqual(ex.message, 'This is an Xception') + + try: + self.client.testMultiException('Xception2', 'ignore') + except Xception2 as ex: + self.assertEqual(ex.errorCode, 2002) + self.assertEqual(ex.struct_thing.string_thing, 'This is an Xception2') + + y = self.client.testMultiException('success', 'foobar') + self.assertEqual(y.string_thing, 'foobar') + def testOneway(self): + print('testOneway') start = time.time() self.client.testOneway(1) # type is int, not float end = time.time() @@ -229,6 +254,7 @@ class AbstractTest(unittest.TestCase): "oneway sleep took %f sec" % (end - start)) def testOnewayThenNormal(self): + print('testOnewayThenNormal') self.client.testOneway(1) # type is int, not float self.assertEqual(self.client.testString('Python'), 'Python') |