public Task <Xtruct2> testNestAsync(Xtruct2 nest, CancellationToken cancellationToken)
            {
                var thing = nest.Struct_thing;

                logger.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})",
                              nest.Byte_thing,
                              thing.String_thing,
                              thing.Byte_thing,
                              thing.I32_thing,
                              thing.I64_thing,
                              nest.I32_thing);
                return(Task.FromResult(nest));
            }
Пример #2
0
            public Xtruct2 testNest(Xtruct2 nest)
            {
                Xtruct thing = nest.Struct_thing;

                Console.WriteLine("testNest({" +
                                  nest.Byte_thing + ", {" +
                                  "\"" + thing.String_thing + "\", " +
                                  thing.Byte_thing + ", " +
                                  thing.I32_thing + ", " +
                                  thing.I64_thing + "}, " +
                                  nest.I32_thing + "})");
                return(nest);
            }
Пример #3
0
            public Xtruct2 testNest(Xtruct2 nest)
            {
                Xtruct thing = nest.Struct_thing;

                testLogDelegate.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})",
                                       nest.Byte_thing,
                                       thing.String_thing,
                                       thing.Byte_thing,
                                       thing.I32_thing,
                                       thing.I64_thing,
                                       nest.I32_thing);
                return(nest);
            }
Пример #4
0
        public static void ClientTest(TTransport transport)
        {
            TProtocol proto;

            if (protocol == "compact")
            {
                proto = new TCompactProtocol(transport);
            }
            else if (protocol == "json")
            {
                proto = new TJSONProtocol(transport);
            }
            else
            {
                proto = new TBinaryProtocol(transport);
            }

            ThriftTest.Client client = new ThriftTest.Client(proto);
            try
            {
                if (!transport.IsOpen)
                {
                    transport.Open();
                }
            }
            catch (TTransportException ttx)
            {
                Console.WriteLine("Connect failed: " + ttx.Message);
                return;
            }

            long start = DateTime.Now.ToFileTime();

            Console.Write("testVoid()");
            client.testVoid();
            Console.WriteLine(" = void");

            Console.Write("testString(\"Test\")");
            string s = client.testString("Test");

            Console.WriteLine(" = \"" + s + "\"");

            Console.Write("testByte(1)");
            sbyte i8 = client.testByte((sbyte)1);

            Console.WriteLine(" = " + i8);

            Console.Write("testI32(-1)");
            int i32 = client.testI32(-1);

            Console.WriteLine(" = " + i32);

            Console.Write("testI64(-34359738368)");
            long i64 = client.testI64(-34359738368);

            Console.WriteLine(" = " + i64);

            Console.Write("testDouble(5.325098235)");
            double dub = client.testDouble(5.325098235);

            Console.WriteLine(" = " + dub);

            Console.Write("testStruct({\"Zero\", 1, -3, -5})");
            Xtruct o = new Xtruct();

            o.String_thing = "Zero";
            o.Byte_thing   = (sbyte)1;
            o.I32_thing    = -3;
            o.I64_thing    = -5;
            Xtruct i = client.testStruct(o);

            Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");

            Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})");
            Xtruct2 o2 = new Xtruct2();

            o2.Byte_thing   = (sbyte)1;
            o2.Struct_thing = o;
            o2.I32_thing    = 5;
            Xtruct2 i2 = client.testNest(o2);

            i = i2.Struct_thing;
            Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");

            Dictionary <int, int> mapout = new Dictionary <int, int>();

            for (int j = 0; j < 5; j++)
            {
                mapout[j] = j - 10;
            }
            Console.Write("testMap({");
            bool first = true;

            foreach (int key in mapout.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapout[key]);
            }
            Console.Write("})");

            Dictionary <int, int> mapin = client.testMap(mapout);

            Console.Write(" = {");
            first = true;
            foreach (int key in mapin.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapin[key]);
            }
            Console.WriteLine("}");

            List <int> listout = new List <int>();

            for (int j = -2; j < 3; j++)
            {
                listout.Add(j);
            }
            Console.Write("testList({");
            first = true;
            foreach (int j in listout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            List <int> listin = client.testList(listout);

            Console.Write(" = {");
            first = true;
            foreach (int j in listin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");

            //set
            THashSet <int> setout = new THashSet <int>();

            for (int j = -2; j < 3; j++)
            {
                setout.Add(j);
            }
            Console.Write("testSet({");
            first = true;
            foreach (int j in setout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            THashSet <int> setin = client.testSet(setout);

            Console.Write(" = {");
            first = true;
            foreach (int j in setin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");


            Console.Write("testEnum(ONE)");
            Numberz ret = client.testEnum(Numberz.ONE);

            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(TWO)");
            ret = client.testEnum(Numberz.TWO);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(THREE)");
            ret = client.testEnum(Numberz.THREE);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(FIVE)");
            ret = client.testEnum(Numberz.FIVE);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(EIGHT)");
            ret = client.testEnum(Numberz.EIGHT);
            Console.WriteLine(" = " + ret);

            Console.Write("testTypedef(309858235082523)");
            long uid = client.testTypedef(309858235082523L);

            Console.WriteLine(" = " + uid);

            Console.Write("testMapMap(1)");
            Dictionary <int, Dictionary <int, int> > mm = client.testMapMap(1);

            Console.Write(" = {");
            foreach (int key in mm.Keys)
            {
                Console.Write(key + " => {");
                Dictionary <int, int> m2 = mm[key];
                foreach (int k2 in m2.Keys)
                {
                    Console.Write(k2 + " => " + m2[k2] + ", ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            Insanity insane = new Insanity();

            insane.UserMap = new Dictionary <Numberz, long>();
            insane.UserMap[Numberz.FIVE] = 5000L;
            Xtruct truck = new Xtruct();

            truck.String_thing = "Truck";
            truck.Byte_thing   = (sbyte)8;
            truck.I32_thing    = 8;
            truck.I64_thing    = 8;
            insane.Xtructs     = new List <Xtruct>();
            insane.Xtructs.Add(truck);
            Console.Write("testInsanity()");
            Dictionary <long, Dictionary <Numberz, Insanity> > whoa = client.testInsanity(insane);

            Console.Write(" = {");
            foreach (long key in whoa.Keys)
            {
                Dictionary <Numberz, Insanity> val = whoa[key];
                Console.Write(key + " => {");

                foreach (Numberz k2 in val.Keys)
                {
                    Insanity v2 = val[k2];

                    Console.Write(k2 + " => {");
                    Dictionary <Numberz, long> userMap = v2.UserMap;

                    Console.Write("{");
                    if (userMap != null)
                    {
                        foreach (Numberz k3 in userMap.Keys)
                        {
                            Console.Write(k3 + " => " + userMap[k3] + ", ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}, ");

                    List <Xtruct> xtructs = v2.Xtructs;

                    Console.Write("{");
                    if (xtructs != null)
                    {
                        foreach (Xtruct x in xtructs)
                        {
                            Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}");

                    Console.Write("}, ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            sbyte arg0 = 1;
            int   arg1 = 2;
            long  arg2 = long.MaxValue;
            Dictionary <short, string> multiDict = new Dictionary <short, string>();

            multiDict[1] = "one";
            Numberz arg4 = Numberz.FIVE;
            long    arg5 = 5000000;

            Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
            Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);

            Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
                          + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");

            Console.WriteLine("Test Oneway(1)");
            client.testOneway(1);

            Console.Write("Test Calltime()");
            var startt = DateTime.UtcNow;

            for (int k = 0; k < 1000; ++k)
            {
                client.testVoid();
            }
            Console.WriteLine(" = " + (DateTime.UtcNow - startt).TotalSeconds.ToString() + " ms a testVoid() call");
        }
Пример #5
0
        public static int ExecuteClientTest(ThriftTest.Client client)
        {
            int returnCode = 0;

            Console.Write("testVoid()");
            client.testVoid();
            Console.WriteLine(" = void");

            Console.Write("testString(\"Test\")");
            string s = client.testString("Test");

            Console.WriteLine(" = \"" + s + "\"");
            if ("Test" != s)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testBool(true)");
            bool t = client.testBool((bool)true);

            Console.WriteLine(" = " + t);
            if (!t)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }
            Console.Write("testBool(false)");
            bool f = client.testBool((bool)false);

            Console.WriteLine(" = " + f);
            if (f)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testByte(1)");
            sbyte i8 = client.testByte((sbyte)1);

            Console.WriteLine(" = " + i8);
            if (1 != i8)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testI32(-1)");
            int i32 = client.testI32(-1);

            Console.WriteLine(" = " + i32);
            if (-1 != i32)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testI64(-34359738368)");
            long i64 = client.testI64(-34359738368);

            Console.WriteLine(" = " + i64);
            if (-34359738368 != i64)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            // TODO: Validate received message
            Console.Write("testDouble(5.325098235)");
            double dub = client.testDouble(5.325098235);

            Console.WriteLine(" = " + dub);
            if (5.325098235 != dub)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }
            Console.Write("testDouble(-0.000341012439638598279)");
            dub = client.testDouble(-0.000341012439638598279);
            Console.WriteLine(" = " + dub);
            if (-0.000341012439638598279 != dub)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            byte[] binOut = PrepareTestData(true);
            Console.Write("testBinary(" + BytesToHex(binOut) + ")");
            try
            {
                byte[] binIn = client.testBinary(binOut);
                Console.WriteLine(" = " + BytesToHex(binIn));
                if (binIn.Length != binOut.Length)
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorBaseTypes;
                }
                for (int ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs)
                {
                    if (binIn[ofs] != binOut[ofs])
                    {
                        Console.WriteLine("*** FAILED ***");
                        returnCode |= ErrorBaseTypes;
                    }
                }
            }
            catch (Thrift.TApplicationException ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }

            // binary equals? only with hashcode option enabled ...
            Console.WriteLine("Test CrazyNesting");
            if (typeof(CrazyNesting).GetMethod("Equals").DeclaringType == typeof(CrazyNesting))
            {
                CrazyNesting one = new CrazyNesting();
                CrazyNesting two = new CrazyNesting();
                one.String_field = "crazy";
                two.String_field = "crazy";
                one.Binary_field = new byte[10] {
                    0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF
                };
                two.Binary_field = new byte[10] {
                    0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF
                };
                if (!one.Equals(two))
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorContainers;
                    throw new Exception("CrazyNesting.Equals failed");
                }
            }

            // TODO: Validate received message
            Console.Write("testStruct({\"Zero\", 1, -3, -5})");
            Xtruct o = new Xtruct();

            o.String_thing = "Zero";
            o.Byte_thing   = (sbyte)1;
            o.I32_thing    = -3;
            o.I64_thing    = -5;
            Xtruct i = client.testStruct(o);

            Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");

            // TODO: Validate received message
            Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})");
            Xtruct2 o2 = new Xtruct2();

            o2.Byte_thing   = (sbyte)1;
            o2.Struct_thing = o;
            o2.I32_thing    = 5;
            Xtruct2 i2 = client.testNest(o2);

            i = i2.Struct_thing;
            Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");

            Dictionary <int, int> mapout = new Dictionary <int, int>();

            for (int j = 0; j < 5; j++)
            {
                mapout[j] = j - 10;
            }
            Console.Write("testMap({");
            bool first = true;

            foreach (int key in mapout.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapout[key]);
            }
            Console.Write("})");

            Dictionary <int, int> mapin = client.testMap(mapout);

            Console.Write(" = {");
            first = true;
            foreach (int key in mapin.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapin[key]);
            }
            Console.WriteLine("}");

            // TODO: Validate received message
            List <int> listout = new List <int>();

            for (int j = -2; j < 3; j++)
            {
                listout.Add(j);
            }
            Console.Write("testList({");
            first = true;
            foreach (int j in listout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            List <int> listin = client.testList(listout);

            Console.Write(" = {");
            first = true;
            foreach (int j in listin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");

            //set
            // TODO: Validate received message
            THashSet <int> setout = new THashSet <int>();

            for (int j = -2; j < 3; j++)
            {
                setout.Add(j);
            }
            Console.Write("testSet({");
            first = true;
            foreach (int j in setout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            THashSet <int> setin = client.testSet(setout);

            Console.Write(" = {");
            first = true;
            foreach (int j in setin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");


            Console.Write("testEnum(ONE)");
            Numberz ret = client.testEnum(Numberz.ONE);

            Console.WriteLine(" = " + ret);
            if (Numberz.ONE != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(TWO)");
            ret = client.testEnum(Numberz.TWO);
            Console.WriteLine(" = " + ret);
            if (Numberz.TWO != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(THREE)");
            ret = client.testEnum(Numberz.THREE);
            Console.WriteLine(" = " + ret);
            if (Numberz.THREE != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(FIVE)");
            ret = client.testEnum(Numberz.FIVE);
            Console.WriteLine(" = " + ret);
            if (Numberz.FIVE != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(EIGHT)");
            ret = client.testEnum(Numberz.EIGHT);
            Console.WriteLine(" = " + ret);
            if (Numberz.EIGHT != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testTypedef(309858235082523)");
            long uid = client.testTypedef(309858235082523L);

            Console.WriteLine(" = " + uid);
            if (309858235082523L != uid)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            // TODO: Validate received message
            Console.Write("testMapMap(1)");
            Dictionary <int, Dictionary <int, int> > mm = client.testMapMap(1);

            Console.Write(" = {");
            foreach (int key in mm.Keys)
            {
                Console.Write(key + " => {");
                Dictionary <int, int> m2 = mm[key];
                foreach (int k2 in m2.Keys)
                {
                    Console.Write(k2 + " => " + m2[k2] + ", ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            // TODO: Validate received message
            Insanity insane = new Insanity();

            insane.UserMap = new Dictionary <Numberz, long>();
            insane.UserMap[Numberz.FIVE] = 5000L;
            Xtruct truck = new Xtruct();

            truck.String_thing = "Truck";
            truck.Byte_thing   = (sbyte)8;
            truck.I32_thing    = 8;
            truck.I64_thing    = 8;
            insane.Xtructs     = new List <Xtruct>();
            insane.Xtructs.Add(truck);
            Console.Write("testInsanity()");
            Dictionary <long, Dictionary <Numberz, Insanity> > whoa = client.testInsanity(insane);

            Console.Write(" = {");
            foreach (long key in whoa.Keys)
            {
                Dictionary <Numberz, Insanity> val = whoa[key];
                Console.Write(key + " => {");

                foreach (Numberz k2 in val.Keys)
                {
                    Insanity v2 = val[k2];

                    Console.Write(k2 + " => {");
                    Dictionary <Numberz, long> userMap = v2.UserMap;

                    Console.Write("{");
                    if (userMap != null)
                    {
                        foreach (Numberz k3 in userMap.Keys)
                        {
                            Console.Write(k3 + " => " + userMap[k3] + ", ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}, ");

                    List <Xtruct> xtructs = v2.Xtructs;

                    Console.Write("{");
                    if (xtructs != null)
                    {
                        foreach (Xtruct x in xtructs)
                        {
                            Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}");

                    Console.Write("}, ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            sbyte arg0 = 1;
            int   arg1 = 2;
            long  arg2 = long.MaxValue;
            Dictionary <short, string> multiDict = new Dictionary <short, string>();

            multiDict[1] = "one";
            Numberz arg4 = Numberz.FIVE;
            long    arg5 = 5000000;

            Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
            Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);

            Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
                          + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");

            try
            {
                Console.WriteLine("testException(\"Xception\")");
                client.testException("Xception");
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Xception ex)
            {
                if (ex.ErrorCode != 1001 || ex.Message != "Xception")
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testException(\"TException\")");
                client.testException("TException");
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Thrift.TException)
            {
                // OK
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testException(\"ok\")");
                client.testException("ok");
                // OK
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }

            try
            {
                Console.WriteLine("testMultiException(\"Xception\", ...)");
                client.testMultiException("Xception", "ignore");
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Xception ex)
            {
                if (ex.ErrorCode != 1001 || ex.Message != "This is an Xception")
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testMultiException(\"Xception2\", ...)");
                client.testMultiException("Xception2", "ignore");
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Xception2 ex)
            {
                if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2")
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testMultiException(\"success\", \"OK\")");
                if ("OK" != client.testMultiException("success", "OK").String_thing)
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Console.WriteLine("Test Oneway(1)");
            client.testOneway(1);
            sw.Stop();
            if (sw.ElapsedMilliseconds > 1000)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("Test Calltime()");
            var startt = DateTime.UtcNow;

            for (int k = 0; k < 1000; ++k)
            {
                client.testVoid();
            }
            Console.WriteLine(" = " + (DateTime.UtcNow - startt).TotalSeconds.ToString() + " ms a testVoid() call");
            return(returnCode);
        }
Пример #6
0
 public Task<Xtruct2> testNestAsync(Xtruct2 nest, CancellationToken cancellationToken)
 {
     var thing = nest.Struct_thing;
     logger.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})",
         nest.Byte_thing,
         thing.String_thing,
         thing.Byte_thing,
         thing.I32_thing,
         thing.I64_thing,
         nest.I32_thing);
     return Task.FromResult(nest);
 }
        public static async Task <int> ExecuteClientTestAsync(ThriftAsync.Test.ThriftTest.Client client)
        {
            var token      = CancellationToken.None;
            var returnCode = 0;

            Console.Write("testVoid()");
            await client.testVoidAsync(token);

            Console.WriteLine(" = void");

            Console.Write("testString(\"Test\")");
            var s = await client.testStringAsync("Test", token);

            Console.WriteLine(" = \"" + s + "\"");
            if ("Test" != s)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testBool(true)");
            var t = await client.testBoolAsync((bool)true, token);

            Console.WriteLine(" = " + t);
            if (!t)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }
            Console.Write("testBool(false)");
            var f = await client.testBoolAsync((bool)false, token);

            Console.WriteLine(" = " + f);
            if (f)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testByte(1)");
            var i8 = await client.testByteAsync((sbyte)1, token);

            Console.WriteLine(" = " + i8);
            if (1 != i8)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testI32(-1)");
            var i32 = await client.testI32Async(-1, token);

            Console.WriteLine(" = " + i32);
            if (-1 != i32)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testI64(-34359738368)");
            var i64 = await client.testI64Async(-34359738368, token);

            Console.WriteLine(" = " + i64);
            if (-34359738368 != i64)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            // TODO: Validate received message
            Console.Write("testDouble(5.325098235)");
            var dub = await client.testDoubleAsync(5.325098235, token);

            Console.WriteLine(" = " + dub);
            if (5.325098235 != dub)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }
            Console.Write("testDouble(-0.000341012439638598279)");
            dub = await client.testDoubleAsync(-0.000341012439638598279, token);

            Console.WriteLine(" = " + dub);
            if (-0.000341012439638598279 != dub)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            var binOut = PrepareTestData(true);

            Console.Write("testBinary(" + BytesToHex(binOut) + ")");
            try
            {
                var binIn = await client.testBinaryAsync(binOut, token);

                Console.WriteLine(" = " + BytesToHex(binIn));
                if (binIn.Length != binOut.Length)
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorBaseTypes;
                }
                for (var ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs)
                {
                    if (binIn[ofs] != binOut[ofs])
                    {
                        Console.WriteLine("*** FAILED ***");
                        returnCode |= ErrorBaseTypes;
                    }
                }
            }
            catch (Thrift.TApplicationException ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }

            // binary equals? only with hashcode option enabled ...
            Console.WriteLine("Test CrazyNesting");
            var one = new CrazyNesting();
            var two = new CrazyNesting();

            one.String_field = "crazy";
            two.String_field = "crazy";
            one.Binary_field = new byte[] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
            two.Binary_field = new byte[10] {
                0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF
            };
            if (typeof(CrazyNesting).GetMethod("Equals")?.DeclaringType == typeof(CrazyNesting))
            {
                if (!one.Equals(two))
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorContainers;
                    throw new Exception("CrazyNesting.Equals failed");
                }
            }

            // TODO: Validate received message
            Console.Write("testStruct({\"Zero\", 1, -3, -5})");
            var o = new Xtruct();

            o.String_thing = "Zero";
            o.Byte_thing   = (sbyte)1;
            o.I32_thing    = -3;
            o.I64_thing    = -5;
            var i = await client.testStructAsync(o, token);

            Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");

            // TODO: Validate received message
            Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})");
            var o2 = new Xtruct2();

            o2.Byte_thing   = (sbyte)1;
            o2.Struct_thing = o;
            o2.I32_thing    = 5;
            var i2 = await client.testNestAsync(o2, token);

            i = i2.Struct_thing;
            Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");

            var mapout = new Dictionary <int, int>();

            for (var j = 0; j < 5; j++)
            {
                mapout[j] = j - 10;
            }
            Console.Write("testMap({");
            var first = true;

            foreach (var key in mapout.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapout[key]);
            }
            Console.Write("})");

            var mapin = await client.testMapAsync(mapout, token);

            Console.Write(" = {");
            first = true;
            foreach (var key in mapin.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapin[key]);
            }
            Console.WriteLine("}");

            // TODO: Validate received message
            var listout = new List <int>();

            for (var j = -2; j < 3; j++)
            {
                listout.Add(j);
            }
            Console.Write("testList({");
            first = true;
            foreach (var j in listout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            var listin = await client.testListAsync(listout, token);

            Console.Write(" = {");
            first = true;
            foreach (var j in listin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");

            //set
            // TODO: Validate received message
            var setout = new THashSet <int>();

            for (var j = -2; j < 3; j++)
            {
                setout.Add(j);
            }
            Console.Write("testSet({");
            first = true;
            foreach (int j in setout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            var setin = await client.testSetAsync(setout, token);

            Console.Write(" = {");
            first = true;
            foreach (int j in setin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");


            Console.Write("testEnum(ONE)");
            var ret = await client.testEnumAsync(Numberz.ONE, token);

            Console.WriteLine(" = " + ret);
            if (Numberz.ONE != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(TWO)");
            ret = await client.testEnumAsync(Numberz.TWO, token);

            Console.WriteLine(" = " + ret);
            if (Numberz.TWO != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(THREE)");
            ret = await client.testEnumAsync(Numberz.THREE, token);

            Console.WriteLine(" = " + ret);
            if (Numberz.THREE != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(FIVE)");
            ret = await client.testEnumAsync(Numberz.FIVE, token);

            Console.WriteLine(" = " + ret);
            if (Numberz.FIVE != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(EIGHT)");
            ret = await client.testEnumAsync(Numberz.EIGHT, token);

            Console.WriteLine(" = " + ret);
            if (Numberz.EIGHT != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testTypedef(309858235082523)");
            var uid = await client.testTypedefAsync(309858235082523L, token);

            Console.WriteLine(" = " + uid);
            if (309858235082523L != uid)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            // TODO: Validate received message
            Console.Write("testMapMap(1)");
            var mm = await client.testMapMapAsync(1, token);

            Console.Write(" = {");
            foreach (var key in mm.Keys)
            {
                Console.Write(key + " => {");
                var m2 = mm[key];
                foreach (var k2 in m2.Keys)
                {
                    Console.Write(k2 + " => " + m2[k2] + ", ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            // TODO: Validate received message
            var insane = new Insanity();

            insane.UserMap = new Dictionary <Numberz, long>();
            insane.UserMap[Numberz.FIVE] = 5000L;
            var truck = new Xtruct();

            truck.String_thing = "Truck";
            truck.Byte_thing   = (sbyte)8;
            truck.I32_thing    = 8;
            truck.I64_thing    = 8;
            insane.Xtructs     = new List <Xtruct>();
            insane.Xtructs.Add(truck);
            Console.Write("testInsanity()");
            var whoa = await client.testInsanityAsync(insane, token);

            Console.Write(" = {");
            foreach (var key in whoa.Keys)
            {
                var val = whoa[key];
                Console.Write(key + " => {");

                foreach (var k2 in val.Keys)
                {
                    var v2 = val[k2];

                    Console.Write(k2 + " => {");
                    var userMap = v2.UserMap;

                    Console.Write("{");
                    if (userMap != null)
                    {
                        foreach (var k3 in userMap.Keys)
                        {
                            Console.Write(k3 + " => " + userMap[k3] + ", ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}, ");

                    var xtructs = v2.Xtructs;

                    Console.Write("{");
                    if (xtructs != null)
                    {
                        foreach (var x in xtructs)
                        {
                            Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}");

                    Console.Write("}, ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            sbyte arg0      = 1;
            var   arg1      = 2;
            var   arg2      = long.MaxValue;
            var   multiDict = new Dictionary <short, string>();

            multiDict[1] = "one";

            var tmpMultiDict = new List <string>();

            foreach (var pair in multiDict)
            {
                tmpMultiDict.Add(pair.Key + " => " + pair.Value);
            }

            var  arg4 = Numberz.FIVE;
            long arg5 = 5000000;

            Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + ",{" + string.Join(",", tmpMultiDict) + "}," + arg4 + "," + arg5 + ")");
            var multiResponse = await client.testMultiAsync(arg0, arg1, arg2, multiDict, arg4, arg5, token);

            Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
                          + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");

            try
            {
                Console.WriteLine("testException(\"Xception\")");
                await client.testExceptionAsync("Xception", token);

                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Xception ex)
            {
                if (ex.ErrorCode != 1001 || ex.Message != "Xception")
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testException(\"TException\")");
                await client.testExceptionAsync("TException", token);

                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Thrift.TException)
            {
                // OK
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testException(\"ok\")");
                await client.testExceptionAsync("ok", token);

                // OK
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }

            try
            {
                Console.WriteLine("testMultiException(\"Xception\", ...)");
                await client.testMultiExceptionAsync("Xception", "ignore", token);

                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Xception ex)
            {
                if (ex.ErrorCode != 1001 || ex.Message != "This is an Xception")
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testMultiException(\"Xception2\", ...)");
                await client.testMultiExceptionAsync("Xception2", "ignore", token);

                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Xception2 ex)
            {
                if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2")
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testMultiException(\"success\", \"OK\")");
                if ("OK" != (await client.testMultiExceptionAsync("success", "OK", token)).String_thing)
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }

            var sw = new Stopwatch();

            sw.Start();
            Console.WriteLine("Test Oneway(1)");
            await client.testOnewayAsync(1, token);

            sw.Stop();
            if (sw.ElapsedMilliseconds > 1000)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("Test Calltime()");
            var times = 50;

            sw.Reset();
            sw.Start();
            for (var k = 0; k < times; ++k)
            {
                await client.testVoidAsync(token);
            }
            sw.Stop();
            Console.WriteLine(" = {0} ms a testVoid() call", sw.ElapsedMilliseconds / times);
            return(returnCode);
        }
Пример #8
0
        public static async Task<int> ExecuteClientTestAsync(ThriftAsync.Test.ThriftTest.Client client)
        {
            var token = CancellationToken.None;
            var returnCode = 0;

            Console.Write("testVoid()");
            await client.testVoidAsync(token);
            Console.WriteLine(" = void");

            Console.Write("testString(\"Test\")");
            var s = await client.testStringAsync("Test", token);
            Console.WriteLine(" = \"" + s + "\"");
            if ("Test" != s)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testBool(true)");
            var t = await client.testBoolAsync((bool)true, token);
            Console.WriteLine(" = " + t);
            if (!t)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }
            Console.Write("testBool(false)");
            var f = await client.testBoolAsync((bool)false, token);
            Console.WriteLine(" = " + f);
            if (f)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testByte(1)");
            var i8 = await client.testByteAsync((sbyte)1, token);
            Console.WriteLine(" = " + i8);
            if (1 != i8)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testI32(-1)");
            var i32 = await client.testI32Async(-1, token);
            Console.WriteLine(" = " + i32);
            if (-1 != i32)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("testI64(-34359738368)");
            var i64 = await client.testI64Async(-34359738368, token);
            Console.WriteLine(" = " + i64);
            if (-34359738368 != i64)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            // TODO: Validate received message
            Console.Write("testDouble(5.325098235)");
            var dub = await client.testDoubleAsync(5.325098235, token);
            Console.WriteLine(" = " + dub);
            if (5.325098235 != dub)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }
            Console.Write("testDouble(-0.000341012439638598279)");
            dub = await client.testDoubleAsync(-0.000341012439638598279, token);
            Console.WriteLine(" = " + dub);
            if (-0.000341012439638598279 != dub)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            var binOut = PrepareTestData(true);
            Console.Write("testBinary(" + BytesToHex(binOut) + ")");
            try
            {
                var binIn = await client.testBinaryAsync(binOut, token);
                Console.WriteLine(" = " + BytesToHex(binIn));
                if (binIn.Length != binOut.Length)
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorBaseTypes;
                }
                for (var ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs)
                    if (binIn[ofs] != binOut[ofs])
                    {
                        Console.WriteLine("*** FAILED ***");
                        returnCode |= ErrorBaseTypes;
                    }
            }
            catch (Thrift.TApplicationException ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }

            // binary equals? only with hashcode option enabled ...
            Console.WriteLine("Test CrazyNesting");
            var one = new CrazyNesting();
            var two = new CrazyNesting();
            one.String_field = "crazy";
            two.String_field = "crazy";
            one.Binary_field = new byte[] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
            two.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
            if (typeof(CrazyNesting).GetMethod("Equals")?.DeclaringType == typeof(CrazyNesting))
            {
                if (!one.Equals(two))
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorContainers;
                    throw new Exception("CrazyNesting.Equals failed");
                }
            }

            // TODO: Validate received message
            Console.Write("testStruct({\"Zero\", 1, -3, -5})");
            var o = new Xtruct();
            o.String_thing = "Zero";
            o.Byte_thing = (sbyte)1;
            o.I32_thing = -3;
            o.I64_thing = -5;
            var i = await client.testStructAsync(o, token);
            Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");

            // TODO: Validate received message
            Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})");
            var o2 = new Xtruct2();
            o2.Byte_thing = (sbyte)1;
            o2.Struct_thing = o;
            o2.I32_thing = 5;
            var i2 = await client.testNestAsync(o2, token);
            i = i2.Struct_thing;
            Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");

            var mapout = new Dictionary<int, int>();
            for (var j = 0; j < 5; j++)
            {
                mapout[j] = j - 10;
            }
            Console.Write("testMap({");
            var first = true;
            foreach (var key in mapout.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapout[key]);
            }
            Console.Write("})");

            var mapin = await client.testMapAsync(mapout, token);

            Console.Write(" = {");
            first = true;
            foreach (var key in mapin.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapin[key]);
            }
            Console.WriteLine("}");

            // TODO: Validate received message
            var listout = new List<int>();
            for (var j = -2; j < 3; j++)
            {
                listout.Add(j);
            }
            Console.Write("testList({");
            first = true;
            foreach (var j in listout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            var listin = await client.testListAsync(listout, token);

            Console.Write(" = {");
            first = true;
            foreach (var j in listin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");

            //set
            // TODO: Validate received message
            var setout = new THashSet<int>();
            for (var j = -2; j < 3; j++)
            {
                setout.Add(j);
            }
            Console.Write("testSet({");
            first = true;
            foreach (int j in setout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            var setin = await client.testSetAsync(setout, token);

            Console.Write(" = {");
            first = true;
            foreach (int j in setin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");


            Console.Write("testEnum(ONE)");
            var ret = await client.testEnumAsync(Numberz.ONE, token);
            Console.WriteLine(" = " + ret);
            if (Numberz.ONE != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(TWO)");
            ret = await client.testEnumAsync(Numberz.TWO, token);
            Console.WriteLine(" = " + ret);
            if (Numberz.TWO != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(THREE)");
            ret = await client.testEnumAsync(Numberz.THREE, token);
            Console.WriteLine(" = " + ret);
            if (Numberz.THREE != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(FIVE)");
            ret = await client.testEnumAsync(Numberz.FIVE, token);
            Console.WriteLine(" = " + ret);
            if (Numberz.FIVE != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testEnum(EIGHT)");
            ret = await client.testEnumAsync(Numberz.EIGHT, token);
            Console.WriteLine(" = " + ret);
            if (Numberz.EIGHT != ret)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            Console.Write("testTypedef(309858235082523)");
            var uid = await client.testTypedefAsync(309858235082523L, token);
            Console.WriteLine(" = " + uid);
            if (309858235082523L != uid)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorStructs;
            }

            // TODO: Validate received message
            Console.Write("testMapMap(1)");
            var mm = await client.testMapMapAsync(1, token);
            Console.Write(" = {");
            foreach (var key in mm.Keys)
            {
                Console.Write(key + " => {");
                var m2 = mm[key];
                foreach (var k2 in m2.Keys)
                {
                    Console.Write(k2 + " => " + m2[k2] + ", ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            // TODO: Validate received message
            var insane = new Insanity();
            insane.UserMap = new Dictionary<Numberz, long>();
            insane.UserMap[Numberz.FIVE] = 5000L;
            var truck = new Xtruct();
            truck.String_thing = "Truck";
            truck.Byte_thing = (sbyte)8;
            truck.I32_thing = 8;
            truck.I64_thing = 8;
            insane.Xtructs = new List<Xtruct>();
            insane.Xtructs.Add(truck);
            Console.Write("testInsanity()");
            var whoa = await client.testInsanityAsync(insane, token);
            Console.Write(" = {");
            foreach (var key in whoa.Keys)
            {
                var val = whoa[key];
                Console.Write(key + " => {");

                foreach (var k2 in val.Keys)
                {
                    var v2 = val[k2];

                    Console.Write(k2 + " => {");
                    var userMap = v2.UserMap;

                    Console.Write("{");
                    if (userMap != null)
                    {
                        foreach (var k3 in userMap.Keys)
                        {
                            Console.Write(k3 + " => " + userMap[k3] + ", ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}, ");

                    var xtructs = v2.Xtructs;

                    Console.Write("{");
                    if (xtructs != null)
                    {
                        foreach (var x in xtructs)
                        {
                            Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}");

                    Console.Write("}, ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            sbyte arg0 = 1;
            var arg1 = 2;
            var arg2 = long.MaxValue;
            var multiDict = new Dictionary<short, string>();
            multiDict[1] = "one";

            var tmpMultiDict = new List<string>();
            foreach (var pair in multiDict)
                tmpMultiDict.Add(pair.Key +" => "+ pair.Value);

            var arg4 = Numberz.FIVE;
            long arg5 = 5000000;
            Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + ",{" + string.Join(",", tmpMultiDict) + "}," + arg4 + "," + arg5 + ")");
            var multiResponse = await client.testMultiAsync(arg0, arg1, arg2, multiDict, arg4, arg5, token);
            Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
                          + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");

            try
            {
                Console.WriteLine("testException(\"Xception\")");
                await client.testExceptionAsync("Xception", token);
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Xception ex)
            {
                if (ex.ErrorCode != 1001 || ex.Message != "Xception")
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testException(\"TException\")");
                await client.testExceptionAsync("TException", token);
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Thrift.TException)
            {
                // OK
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testException(\"ok\")");
                await client.testExceptionAsync("ok", token);
                // OK
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }

            try
            {
                Console.WriteLine("testMultiException(\"Xception\", ...)");
                await client.testMultiExceptionAsync("Xception", "ignore", token);
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Xception ex)
            {
                if (ex.ErrorCode != 1001 || ex.Message != "This is an Xception")
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testMultiException(\"Xception2\", ...)");
                await client.testMultiExceptionAsync("Xception2", "ignore", token);
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
            }
            catch (Xception2 ex)
            {
                if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2")
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }
            try
            {
                Console.WriteLine("testMultiException(\"success\", \"OK\")");
                if ("OK" != (await client.testMultiExceptionAsync("success", "OK", token)).String_thing)
                {
                    Console.WriteLine("*** FAILED ***");
                    returnCode |= ErrorExceptions;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorExceptions;
                Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
            }

            var sw = new Stopwatch();
            sw.Start();
            Console.WriteLine("Test Oneway(1)");
            await client.testOnewayAsync(1, token);
            sw.Stop();
            if (sw.ElapsedMilliseconds > 1000)
            {
                Console.WriteLine("*** FAILED ***");
                returnCode |= ErrorBaseTypes;
            }

            Console.Write("Test Calltime()");
            var times = 50;
            sw.Reset();
            sw.Start();
            for (var k = 0; k < times; ++k)
                await client.testVoidAsync(token);
            sw.Stop();
            Console.WriteLine(" = {0} ms a testVoid() call", sw.ElapsedMilliseconds / times);
            return returnCode;
        }
        public Xtruct2 testNest(Xtruct2 thing)
        {
            Console.WriteLine("testNest:" + thing.ToString());

            return(thing);
        }
Пример #10
0
        public static void ClientTest(TTransport transport)
        {
            TProtocol proto;

            if (protocol == "compact")
            {
                proto = new TCompactProtocol(transport);
            }
            else if (protocol == "json")
            {
                proto = new TJSONProtocol(transport);
            }
            else
            {
                proto = new TBinaryProtocol(transport);
            }

            ThriftTest.Client client = new ThriftTest.Client(proto);
            try
            {
                if (!transport.IsOpen)
                {
                    transport.Open();
                }
            }
            catch (TTransportException ttx)
            {
                Console.WriteLine("Connect failed: " + ttx.Message);
                return;
            }

            long start = DateTime.Now.ToFileTime();

            Console.Write("testVoid()");
            client.testVoid();
            Console.WriteLine(" = void");

            Console.Write("testString(\"Test\")");
            string s = client.testString("Test");

            Console.WriteLine(" = \"" + s + "\"");

            Console.Write("testBool(true)");
            bool t = client.testBool((bool)true);

            Console.WriteLine(" = " + t);
            Console.Write("testBool(false)");
            bool f = client.testBool((bool)false);

            Console.WriteLine(" = " + f);

            Console.Write("testByte(1)");
            sbyte i8 = client.testByte((sbyte)1);

            Console.WriteLine(" = " + i8);

            Console.Write("testI32(-1)");
            int i32 = client.testI32(-1);

            Console.WriteLine(" = " + i32);

            Console.Write("testI64(-34359738368)");
            long i64 = client.testI64(-34359738368);

            Console.WriteLine(" = " + i64);

            Console.Write("testDouble(5.325098235)");
            double dub = client.testDouble(5.325098235);

            Console.WriteLine(" = " + dub);

            byte[] binOut = PrepareTestData(true);
            Console.Write("testBinary(" + BytesToHex(binOut) + ")");
            try
            {
                byte[] binIn = client.testBinary(binOut);
                Console.WriteLine(" = " + BytesToHex(binIn));
                if (binIn.Length != binOut.Length)
                {
                    throw new Exception("testBinary: length mismatch");
                }
                for (int ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs)
                {
                    if (binIn[ofs] != binOut[ofs])
                    {
                        throw new Exception("testBinary: content mismatch at offset " + ofs.ToString());
                    }
                }
            }
            catch (Thrift.TApplicationException e)
            {
                Console.Write("testBinary(" + BytesToHex(binOut) + "): " + e.Message);
            }

            // binary equals? only with hashcode option enabled ...
            if (typeof(CrazyNesting).GetMethod("Equals").DeclaringType == typeof(CrazyNesting))
            {
                CrazyNesting one = new CrazyNesting();
                CrazyNesting two = new CrazyNesting();
                one.String_field = "crazy";
                two.String_field = "crazy";
                one.Binary_field = new byte[10] {
                    0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF
                };
                two.Binary_field = new byte[10] {
                    0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF
                };
                if (!one.Equals(two))
                {
                    throw new Exception("CrazyNesting.Equals failed");
                }
            }

            Console.Write("testStruct({\"Zero\", 1, -3, -5})");
            Xtruct o = new Xtruct();

            o.String_thing = "Zero";
            o.Byte_thing   = (sbyte)1;
            o.I32_thing    = -3;
            o.I64_thing    = -5;
            Xtruct i = client.testStruct(o);

            Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");

            Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})");
            Xtruct2 o2 = new Xtruct2();

            o2.Byte_thing   = (sbyte)1;
            o2.Struct_thing = o;
            o2.I32_thing    = 5;
            Xtruct2 i2 = client.testNest(o2);

            i = i2.Struct_thing;
            Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");

            Dictionary <int, int> mapout = new Dictionary <int, int>();

            for (int j = 0; j < 5; j++)
            {
                mapout[j] = j - 10;
            }
            Console.Write("testMap({");
            bool first = true;

            foreach (int key in mapout.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapout[key]);
            }
            Console.Write("})");

            Dictionary <int, int> mapin = client.testMap(mapout);

            Console.Write(" = {");
            first = true;
            foreach (int key in mapin.Keys)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(key + " => " + mapin[key]);
            }
            Console.WriteLine("}");

            List <int> listout = new List <int>();

            for (int j = -2; j < 3; j++)
            {
                listout.Add(j);
            }
            Console.Write("testList({");
            first = true;
            foreach (int j in listout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            List <int> listin = client.testList(listout);

            Console.Write(" = {");
            first = true;
            foreach (int j in listin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");

            //set
            THashSet <int> setout = new THashSet <int>();

            for (int j = -2; j < 3; j++)
            {
                setout.Add(j);
            }
            Console.Write("testSet({");
            first = true;
            foreach (int j in setout)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.Write("})");

            THashSet <int> setin = client.testSet(setout);

            Console.Write(" = {");
            first = true;
            foreach (int j in setin)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(j);
            }
            Console.WriteLine("}");


            Console.Write("testEnum(ONE)");
            Numberz ret = client.testEnum(Numberz.ONE);

            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(TWO)");
            ret = client.testEnum(Numberz.TWO);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(THREE)");
            ret = client.testEnum(Numberz.THREE);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(FIVE)");
            ret = client.testEnum(Numberz.FIVE);
            Console.WriteLine(" = " + ret);

            Console.Write("testEnum(EIGHT)");
            ret = client.testEnum(Numberz.EIGHT);
            Console.WriteLine(" = " + ret);

            Console.Write("testTypedef(309858235082523)");
            long uid = client.testTypedef(309858235082523L);

            Console.WriteLine(" = " + uid);

            Console.Write("testMapMap(1)");
            Dictionary <int, Dictionary <int, int> > mm = client.testMapMap(1);

            Console.Write(" = {");
            foreach (int key in mm.Keys)
            {
                Console.Write(key + " => {");
                Dictionary <int, int> m2 = mm[key];
                foreach (int k2 in m2.Keys)
                {
                    Console.Write(k2 + " => " + m2[k2] + ", ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            Insanity insane = new Insanity();

            insane.UserMap = new Dictionary <Numberz, long>();
            insane.UserMap[Numberz.FIVE] = 5000L;
            Xtruct truck = new Xtruct();

            truck.String_thing = "Truck";
            truck.Byte_thing   = (sbyte)8;
            truck.I32_thing    = 8;
            truck.I64_thing    = 8;
            insane.Xtructs     = new List <Xtruct>();
            insane.Xtructs.Add(truck);
            Console.Write("testInsanity()");
            Dictionary <long, Dictionary <Numberz, Insanity> > whoa = client.testInsanity(insane);

            Console.Write(" = {");
            foreach (long key in whoa.Keys)
            {
                Dictionary <Numberz, Insanity> val = whoa[key];
                Console.Write(key + " => {");

                foreach (Numberz k2 in val.Keys)
                {
                    Insanity v2 = val[k2];

                    Console.Write(k2 + " => {");
                    Dictionary <Numberz, long> userMap = v2.UserMap;

                    Console.Write("{");
                    if (userMap != null)
                    {
                        foreach (Numberz k3 in userMap.Keys)
                        {
                            Console.Write(k3 + " => " + userMap[k3] + ", ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}, ");

                    List <Xtruct> xtructs = v2.Xtructs;

                    Console.Write("{");
                    if (xtructs != null)
                    {
                        foreach (Xtruct x in xtructs)
                        {
                            Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, ");
                        }
                    }
                    else
                    {
                        Console.Write("null");
                    }
                    Console.Write("}");

                    Console.Write("}, ");
                }
                Console.Write("}, ");
            }
            Console.WriteLine("}");

            sbyte arg0 = 1;
            int   arg1 = 2;
            long  arg2 = long.MaxValue;
            Dictionary <short, string> multiDict = new Dictionary <short, string>();

            multiDict[1] = "one";
            Numberz arg4 = Numberz.FIVE;
            long    arg5 = 5000000;

            Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
            Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);

            Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
                          + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");

            Console.WriteLine("Test Oneway(1)");
            client.testOneway(1);

            Console.Write("Test Calltime()");
            var startt = DateTime.UtcNow;

            for (int k = 0; k < 1000; ++k)
            {
                client.testVoid();
            }
            Console.WriteLine(" = " + (DateTime.UtcNow - startt).TotalSeconds.ToString() + " ms a testVoid() call");
        }
Пример #11
0
        //public Xtruct testMultiException(string arg0, string arg1)
        //{
        //    Console.WriteLine("testMultiException:" + arg0 + " " + arg1 + " ");

        //    Xtruct info = new Xtruct()
        //    {
        //        String_thing = arg0 + arg1
        //    };

        //    return info;
        //}

        public void testNest(Xtruct2 thing)
        {
            GenericTree input1 = new GenericTree();

            input1.setName("thing");
            input1.setParamType(TypeEnum.SYNTHETIC_TYPE);
            input1.setThrfitType("STRUCT");
            input1.setType("XStruct2");

            GenericTree prop1 = new GenericTree();

            prop1.setName("Byte_thing");
            prop1.setParamType(TypeEnum.PRIMITIVE_TYPE);
            prop1.setThrfitType("SBYTE");
            prop1.setParent(input1);

            GenericTree prop2 = new GenericTree();

            prop2.setName("Xstruct_thing");
            prop2.setParamType(TypeEnum.SYNTHETIC_TYPE);
            prop2.setThrfitType("STRUCT");
            prop2.setType("XStruct");


            GenericTree prop31 = new GenericTree();

            prop31.setName("String_thing");
            prop31.setParamType(TypeEnum.PRIMITIVE_TYPE);
            prop31.setThrfitType("STRING");
            prop31.setParent(prop2);

            GenericTree prop32 = new GenericTree();

            prop32.setName("Byte_thing");
            prop32.setParamType(TypeEnum.PRIMITIVE_TYPE);
            prop32.setThrfitType("SBYTE");
            prop32.setParent(prop2);

            GenericTree prop33 = new GenericTree();

            prop33.setName("I32_thing");
            prop33.setParamType(TypeEnum.PRIMITIVE_TYPE);
            prop33.setThrfitType("I32");
            prop33.setParent(prop2);

            GenericTree prop34 = new GenericTree();

            prop34.setName("I64_thing");
            prop34.setParamType(TypeEnum.PRIMITIVE_TYPE);
            prop34.setThrfitType("I64");
            prop34.setParent(prop2);

            prop2.setParent(input1);


            GenericTree prop3 = new GenericTree();

            prop3.setName("I32_thing");
            prop3.setParamType(TypeEnum.PRIMITIVE_TYPE);
            prop3.setThrfitType("I32");
            prop3.setParent(input1);


            List <GenericTree> inputGenericTrees = new List <GenericTree>
            {
                input1
            };

            // 参数值
            List <Object> inputVals = new List <object>();


            Dictionary <string, object> xstruct2 = new Dictionary <string, object>();

            xstruct2["Byte_thing"]    = thing.Byte_thing;
            xstruct2["I32_thing"]     = thing.I32_thing;
            xstruct2["Xstruct_thing"] = new Dictionary <string, object> {
                { "Byte_thing", thing.Struct_thing.Byte_thing }
                , { "String_thing", thing.Struct_thing.String_thing }
                , { "I32_thing", thing.Struct_thing.I32_thing }
                , { "I64_thing", thing.Struct_thing.I64_thing }
            };

            inputVals.Add(xstruct2);


            string method = SERVICE_NAME + "testNest";

            GenericNode genericNode = new GenericNode();

            genericNode.setInputs(inputGenericTrees);
            genericNode.setMethodName(method);
            genericNode.setValues(inputVals);
            genericNode.setOutput(input1);

            object obj = genericAnalyser.syncProcess(protocol, genericNode);

            Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
        }