示例#1
0
        public void Test_Add()
        {
            XType add = vf.GetType("add");

            Field x = new Field("x");

            add.PutValidator(x, Validator_int.Get(0));

            Field y = new Field("y");

            add.PutValidator(y, Validator_int.Get(0));

            Field _mf__messageId = DefaultValueFactory._mf__messageId;

            add.PutValidator(_mf__messageId, Validator_long.Get(0));

            long msgid = 0x0102030405060708L;

            Message msg = new Message(add, vf);

            msg.Add(x, 1);
            msg.Add(y, 2);
            msg.Add(_mf__messageId, msgid);
            testmsg2bytes(msg, null, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, 1, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, 2, -127 });
            testmsg2bytes(msg, false, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, 1, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, 2, -127 });
            testmsg2bytes(msg, true, new sbyte[] { 3, -109, 3, 97, 100, 100, 3, -109, 1, 120, 1, -109, 10, 95, 109, 101, 115, 115, 97, 103, 101, 73, 100, -121, 1, 2, 3, 4, 5, 6, 7, 8, -109, 1, 121, 2, -127 });

            msg = new Message(add, vf);
            msg.Add(x, 1000000000);
            msg.Add(y, 2000000000);
            msg.Add(_mf__messageId, msgid);
            testmsg2bytes(msg, null, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, -122, 59, -102, -54, 0, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, -122, 119, 53, -108, 0, -127 });
            testmsg2bytes(msg, false, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, -122, 59, -102, -54, 0, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, -122, 119, 53, -108, 0, -127 });
            testmsg2bytes(msg, true, new sbyte[] { 3, -109, 3, 97, 100, 100, 3, -109, 1, 120, -122, 59, -102, -54, 0, -109, 10, 95, 109, 101, 115, 115, 97, 103, 101, 73, 100, -121, 1, 2, 3, 4, 5, 6, 7, 8, -109, 1, 121, -122, 119, 53, -108, 0, -127 });
        }
示例#2
0
        private Message ConstructMessage()
        {
            int delay = 15;
            int count = 4;

            MyValueFactory vf1 = new MyValueFactory("tcp:");

            Field mf_delay = new Field("delay");
            Field mf_count = new Field("count");

            XType mt_request = new XType("_Etch_KeepAliveReq");

            mt_request.PutValidator(mf_delay, Validator_int.Get(0));
            mt_request.PutValidator(mf_count, Validator_int.Get(0));
            vf1.AddType(mt_request);

            XType mt_response = new XType("_Etch_KeepAliveResp");

            vf1.AddType(mt_response);

            mt_request.SetResult(mt_response);

            Message msg = new Message(mt_request, vf1);

            msg.Add(mf_delay, delay);
            msg.Add(mf_count, count);

            return(msg);
        }
示例#3
0
        public KeepAlive(TransportMessage transport, URL uri, Resources resources)
            : base(transport, uri, resources)
        {
            delay = uri.GetIntegerTerm(DELAY, 15);
            if (delay <= 0)
            {
                throw new ArgumentException("delay <= 0");
            }

            count = uri.GetIntegerTerm(COUNT, 4);
            if (count <= 0)
            {
                throw new ArgumentException("count <= 0");
            }

            server = (Boolean)transport.TransportQuery(TransportConsts.IS_SERVER);

            //		Log.report( "KeepAliveInstalled",
            //			"delay", delay, "count", count, "server", server );

            vf = (ValueFactory)resources.Get(TransportConsts.VALUE_FACTORY);

            mf_delay = new Field("delay");
            mf_count = new Field("count");

            mt_request = new XType("_Etch_KeepAliveReq");
            mt_request.PutValidator(mf_delay, Validator_int.Get(0));
            mt_request.PutValidator(mf_count, Validator_int.Get(0));
            vf.AddType(mt_request);

            mt_response = new XType("_Etch_KeepAliveResp");
            vf.AddType(mt_response);

            mt_request.SetResult(mt_response);
        }
示例#4
0
 public TestStructValue()
 {
     mt1.PutValidator(mf1, Validator_boolean.Get(0));
     mt1.PutValidator(mf2, Validator_boolean.Get(1));
     mt1.PutValidator(mf3, Validator_int.Get(0));
     mt1.PutValidator(mf4, Validator_int.Get(1));
     mt1.PutValidator(mf5, Validator_string.Get(0));
     mt1.PutValidator(mf6, Validator_string.Get(1));
 }
示例#5
0
        public TestMessage()
        {
            mt1.PutValidator(mf1, Validator_int.Get(0));
            mt1.PutValidator(mf2, Validator_int.Get(0));
            mt1.PutValidator(vf.mf_messageId, Validator_long.Get(0));

            rmt.PutValidator(vf.mf_messageId, Validator_long.Get(0));
            rmt.PutValidator(vf.mf_inReplyTo, Validator_long.Get(0));
        }
示例#6
0
            static MyValueFactory()
            {
                DefaultValueFactory.Init(types, class2type);

                mt_add.PutValidator(mf_x, Validator_int.Get(0));
                mt_add.PutValidator(mf_y, Validator_int.Get(0));
                mt_add.PutValidator(DefaultValueFactory._mf__messageId, Validator_long.Get(0));

                mt_add_result.PutValidator(mf_result, Validator_int.Get(0));
                mt_add_result.PutValidator(DefaultValueFactory._mf__messageId, Validator_long.Get(0));
                mt_add_result.PutValidator(DefaultValueFactory._mf__inReplyTo, Validator_long.Get(0));
            }
示例#7
0
文件: TestXType.cs 项目: NeoTim/etch
        public void TestGetValidator()
        {
            XType     t = new XType("t");
            Field     f = new Field("f");
            Field     g = new Field("g");
            Validator v = Validator_int.Get(0);

            t.PutValidator(f, v);

            Assert.AreEqual(v, t.GetValidator(f));
            Assert.IsNull(t.GetValidator(g));
        }
示例#8
0
        private void Test(int n, String s, Object good, Object bad)
        {
            Validator_int     v1 = Validator_int.Get(n);
            Validator_boolean v2 = Validator_boolean.Get(n);
            ComboValidator    v  = new ComboValidator(v1, v2);

            Assert.AreEqual(s, v.ToString());
            Assert.IsTrue(v.Validate(good));
            Assert.IsFalse(v.Validate(bad));

            if (n > 0)
            {
                v.ElementValidator();
            }
        }
示例#9
0
        public void Test5()
        {
            Validator v1 = Validator_boolean.Get(1);
            Validator v2 = Validator_int.Get(1);
            Validator v  = new ComboValidator(v1, v2);

            Assert.IsTrue(v.Validate(new Boolean[] {}));
            Assert.IsTrue(v.Validate(new int[] {}));

            v = v.ElementValidator();

            Assert.IsTrue(v.Validate(true));
            Assert.IsTrue(v.Validate(false));
            Assert.IsTrue(v.Validate(0));

            v = v.ElementValidator();
        }
示例#10
0
        public void Test_add_perf()
        {
            vf = new MyValueFactory();

            XType add = vf.GetType("add");

            Field x = new Field("x");

            add.PutValidator(x, Validator_int.Get(0));

            Field y = new Field("y");

            add.PutValidator(y, Validator_int.Get(0));

            Field _mf__messageId = DefaultValueFactory._mf__messageId;

            add.PutValidator(_mf__messageId, Validator_long.Get(0));

            long msgid = 0x0123456789abcdefL;

            Message msg = new Message(add, vf);

            msg.Add(x, 123456789);
            msg.Add(y, 876543210);
            msg.Add(_mf__messageId, msgid);

            Resources res = new Resources();

            res.Add(TransportConsts.VALUE_FACTORY, vf);
            MyPacketSource ps = new MyPacketSource();
            Messagizer     m  = new Messagizer(ps, "foo:?Messagizer.format=binary", res);

            m.TransportMessage(null, msg);


            int n = 900973;

            for (int i = 0; i < 3; i++)
            {
                TestPerf("test_add_perf", i, m, msg, n);
            }
        }
示例#11
0
        public void Test_int()
        {
            // 2 Dimensional
            TestX(new int[][] { new int[] { int.MinValue, short.MinValue, SByte.MinValue,
                                            -1, 0, 1, sbyte.MaxValue, short.MaxValue, int.MaxValue }, new int[] { 23 } },
                  Validator_int.Get(2));

            // 3 dimensional
            TestX(
                new int[][][]
            {
                new int[][] { new int[] { int.MinValue, short.MinValue, SByte.MinValue,
                                          -1, 0, 1, sbyte.MaxValue, short.MaxValue, int.MaxValue }, new int[] { 23 } },
                new int[][] { new int[] { int.MaxValue, short.MinValue, SByte.MinValue,
                                          -1, 0, 1, sbyte.MaxValue, short.MinValue, int.MaxValue }, new int[] { 23 } },
                new int[][] { new int[] { int.MaxValue, short.MaxValue, SByte.MaxValue,
                                          -1, 0, 1, sbyte.MinValue, short.MinValue, int.MinValue }, new int[] { 23 } }
            },
                Validator_int.Get(3));
        }
示例#12
0
文件: TestXType.cs 项目: NeoTim/etch
        public void TestPutValidatorNull()
        {
            XType     t = new XType("t");
            Field     f = new Field("f");
            Validator v = Validator_int.Get(0);

            Assert.IsNull(t.GetValidator(f));

            t.PutValidator(f, null);
            Assert.IsNull(t.GetValidator(f));

            t.PutValidator(f, v);
            Assert.AreEqual(v, t.GetValidator(f));

            t.PutValidator(f, v);
            Assert.AreEqual(typeof(ComboValidator), (t.GetValidator(f)).GetType());

            t.ClearValidator(f);
            Assert.IsNull(t.GetValidator(f));
        }
示例#13
0
        public void Test_sum_perf()
        {
            XType sum = vf.GetType("sum");

            Field values = new Field("values");

            sum.PutValidator(values, Validator_int.Get(1));

            Field _mf__messageId = DefaultValueFactory._mf__messageId;

            sum.PutValidator(_mf__messageId, Validator_long.Get(0));

            long msgid = 0x0123456789abcdefL;

            int[] array = new int[2];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = 123456789;
            }

            Message msg = new Message(sum, vf);

            msg.Add(values, array);
            msg.Add(_mf__messageId, msgid);

            Resources res = new Resources();

            res.Add(TransportConsts.VALUE_FACTORY, vf);
            MyPacketSource ps = new MyPacketSource();
            Messagizer     m  = new Messagizer(ps, "foo:?Messagizer.format=binary", res);

            m.TransportMessage(null, msg);

            int n = 509520;

            for (int i = 0; i < 1; i++)
            {
                TestPerf("test_sum_perf", i, m, msg, n);
            }
        }
示例#14
0
        public void test_add_in()
        {
            XType add = vf.GetType("add");

            Field x = new Field("x");

            add.PutValidator(x, Validator_int.Get(0));

            Field y = new Field("y");

            add.PutValidator(y, Validator_int.Get(0));

            Field _mf__messageId = DefaultValueFactory._mf__messageId;

            add.PutValidator(_mf__messageId, Validator_long.Get(0));

            long msgid = 0x0123456789abcdefL;

            //sbyte[] _buf = { 1, -9, -100, -73, -23, 39, -9, 104, -76, 6, 99, -13, -17, -51, -85, -119, 103, 69, 35, 1, -9, -76, 44, 10, 21, 66, -9, -77, 44, 10, 21, 65, -22 } ;
            sbyte[] _buf = { 3,                   // version
                             -122,                // INT (Type)
                             39,   -23, -73,-100, // add
                             3,                   // length
                             -122,
                             99,     6, -76, 104,
                             -121,                // LONG (value)
                             1,     35,  69, 103,-119, -85, -51, -17,
                             -122,                // INT (key)
                             21,    10,  44, -76, // y
                             2,                   // tiny int = 2 (value)
                             -122,                // INT (key)
                             21,    10,  44, -77, // x
                             1,                   // tiny int =1
                             -127                 // NONE
            };
            byte[]  buf = new byte[_buf.Length];
            Buffer.BlockCopy(_buf, 0, buf, 0, _buf.Length);

            Message msg = Bytes2msg(buf);

            msg.CheckType(add);
            Assert.AreEqual(3, msg.Count);
            Assert.AreEqual(1, msg[x]);
            Assert.AreEqual(2, msg[y]);
            Assert.AreEqual(msgid, msg[_mf__messageId]);

            //_buf = new sbyte[] { 1, -9, -100, -73, -23, 39, -9, 104, -76, 6, 99, -13, -17, -51, -85, -119, 103, 69, 35, 1, -9, -76, 44, 10, 21, -9, 0, -108, 53, 119, -9, -77, 44, 10, 21, -9, 0, -54, -102, 59, -22 };
            // _buf = new sbyte[] { 3, -9, 39, -23, -73, -100, -9, 99, 6, -76, 104, -13, 1, 35, 69, 103, -119, -85, -51, -17, -9, 21, 10, 44, -76, -9, 119, 53, -108, 0, -9, 21, 10, 44, -77, -9, 59, -102, -54, 0, -22 };
            _buf = new sbyte[]
            {
                3,                  // version
                -122,               // INT (type)
                39, -23, -73, -100, // add
                3,                  // length
                -122,               // INT (key)
                99, 6, -76, 104,
                -121,               // LONG (value)
                1, 35, 69, 103, -119, -85, -51, -17,
                -122,               // INT (key)
                21, 10, 44, -76,    // y
                -122,               // INT (value)
                119, 53, -108, 0,
                -122,               // INT (key)
                21, 10, 44, -77,    // x
                -122,               // INT (value)
                59, -102, -54, 0,
                -127                // NONE
            };

            buf = new byte[_buf.Length];
            Buffer.BlockCopy(_buf, 0, buf, 0, _buf.Length);

            msg = Bytes2msg(buf);
            msg.CheckType(add);
            Assert.AreEqual(3, msg.Count);
            Assert.AreEqual(1000000000, msg[x]);
            Assert.AreEqual(2000000000, msg[y]);
            Assert.AreEqual(msgid, msg[_mf__messageId]);
        }
示例#15
0
        static MyValueFactoryCuae()
        {
            DefaultValueFactory.Init(types, class2type);

            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.SetAsyncMode(AsyncMode.QUEUED);
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.SetResult(_mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit);
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.SetAsyncMode(AsyncMode.FREE);
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.SetResult(_mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2);
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit3.SetResult(_mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3);



            //	class2type.Add( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Request ), _mt_etch_bindings_csharp_examples_cuae_Cuae_Request );
            //	_mt_etch_bindings_csharp_examples_cuae_Cuae_Request.SetClass( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Request ) );
            _mt_etch_bindings_csharp_examples_cuae_Cuae_Request.SetImportExportHelper
            (
                new ImportExportHelper(

                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );


            //	class2type.Add( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Response ), _mt_etch_bindings_csharp_examples_cuae_Cuae_Response );
            //  _mt_etch_bindings_csharp_examples_cuae_Cuae_Response.SetClass( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Response ) );
            _mt_etch_bindings_csharp_examples_cuae_Cuae_Response.SetImportExportHelper
            (
                new ImportExportHelper(
                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );

            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.SetSuperType(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request);

            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.SetImportExportHelper
            (
                new ImportExportHelper(
                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );

            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.SetSuperType(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response);
            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.SetImportExportHelper
            (
                new ImportExportHelper(
                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );

            // initialize the extern serializers:

            // done updating types and fields, lock them.
            types.Lock();

            class2type.Lock();


            _mt_etch_bindings_csharp_examples_cuae_Cuae_Request.PutValidator(_mf_code, Validator_int.Get(0));

            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.PutValidator(_mf_code, Validator_int.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.PutValidator(_mf_msg, Validator_string.Get(0));


            _mt_etch_bindings_csharp_examples_cuae_Cuae_Response.PutValidator(_mf_msg, Validator_string.Get(0));

            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.PutValidator(_mf_msg, Validator_string.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.PutValidator(_mf_code, Validator_int.Get(0));



            // params for doit
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.PutValidator(_mf_req, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.PutValidator(_mf__messageId, Validator_long.Get(0));



            // params for _result_doit
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf_result, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf__messageId, Validator_long.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf_result, Validator_RuntimeException.Get());       // thrown RuntimeException
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf__inReplyTo, Validator_long.Get(0));



            // params for doit2
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.PutValidator(_mf_req, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.PutValidator(_mf__messageId, Validator_long.Get(0));



            // params for _result_doit2
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf_result, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf__messageId, Validator_long.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf_result, Validator_RuntimeException.Get());       // thrown RuntimeException
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf__inReplyTo, Validator_long.Get(0));

            // params for doit3
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit3.PutValidator(_mf_req, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request, 1));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit3.PutValidator(_mf__messageId, Validator_long.Get(0));



            // params for _result_doit3
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf_result, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response, 1));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf__messageId, Validator_long.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf_result, Validator_RuntimeException.Get()); // thrown RuntimeException
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf__inReplyTo, Validator_long.Get(0));

            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.Timeout       = 500;
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.ResponseField = _mf_result;
        } // end of static constructor