Example #1
0
        public static void Test()
        {
            Console.WriteLine("Testing Pyro flame server (make sure it's running on localhost 9999)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            setConfig();

            PyroProxy flame = new PyroProxy("localhost", 9999, "Pyro.Flame");

            Console.WriteLine("builtin:");
            using (FlameBuiltin r_max = (FlameBuiltin)flame.call("builtin", "max"))
            {
                int maximum = (int)r_max.call(new int[] { 22, 99, 1 });
                Console.WriteLine("maximum=" + maximum);
            }

            using (FlameModule r_module = (FlameModule)flame.call("module", "socket"))
            {
                String hostname = (String)r_module.call("gethostname");
                Console.WriteLine("hostname=" + hostname);
            }

            int sum = (int)flame.call("evaluate", "9+9");

            Console.WriteLine("sum=" + sum);

            flame.call("execute", "import sys; sys.stdout.write('HELLO FROM C#\\n')");

            using (FlameRemoteConsole console = (FlameRemoteConsole)flame.call("console"))
            {
                console.interact();
            }
        }
Example #2
0
        public static void Test()
        {
            Console.WriteLine("Testing Pyro echo server (make sure it's running, with nameserver enabled)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            setConfig();
            Console.WriteLine("serializer used: {0}", Config.SERIALIZER);
            if (Config.SERIALIZER == Config.SerializerType.serpent)
            {
                Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");
            }

            NameServerProxy ns = NameServerProxy.locateNS(null);
            PyroProxy       p  = new PyroProxy(ns.lookup("test.echoserver"));

            // PyroProxy p=new PyroProxy("localhost",9999,"test.echoserver");

            Object x = 42;

            Console.WriteLine("echo param:");
            PrettyPrint.print(x);
            Object result = p.call("echo", x);

            Console.WriteLine("return value:");
            PrettyPrint.print(result);

            String s = "This string is way too long. This string is way too long. This string is way too long. This string is way too long. ";

            s = s + s + s + s + s;
            Console.WriteLine("echo param:");
            PrettyPrint.print(s);
            result = p.call("echo", s);
            Console.WriteLine("return value:");
            PrettyPrint.print(result);

            Console.WriteLine("dict test.");
            IDictionary <string, object> map = new Dictionary <string, object>()
            {
                { "value", 42 },
                { "message", "hello" },
                { "timestamp", DateTime.Now }
            };

            result = p.call("echo", map);
            Console.WriteLine("return value:");
            PrettyPrint.print(result);


            Console.WriteLine("error test.");
            try {
                result = p.call("error");
            } catch (PyroException e) {
                Console.WriteLine("Pyro Exception (expected)! {0}", e.Message);
                Console.WriteLine("Pyro Exception cause: {0}", e.InnerException);
                Console.WriteLine("Pyro Exception remote traceback:\n>>>\n{0}<<<", e._pyroTraceback);
            }

            Console.WriteLine("shutting down the test echo server.");
            p.call("shutdown");
        }
Example #3
0
        private void ballButton_Click(object sender, EventArgs e)
        {
            PyroProxy playfield = new_playfield();

            playfield.call_oneway("create_ball");
            playfield.close();
        }
Example #4
0
 public void Cleanup()
 {
     _testserver.Dispose();
     _testserver = null;
     _ns.Dispose();
     _ns = null;
 }
Example #5
0
        public static void Test()
        {
            Console.WriteLine("Testing Pyro flame server (make sure it's running on localhost 9999)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            setConfig();

            dynamic flame = new PyroProxy("localhost", 9999, "Pyro.Flame");

            Console.WriteLine("builtin:");
            using (dynamic r_max = (FlameBuiltin)flame.builtin("max"))
            {
                int maximum = (int)r_max(new int[] { 22, 99, 1 });              // invoke remote max() builtin function
                Console.WriteLine("maximum=" + maximum);
            }

            using (dynamic r_module = (FlameModule)flame.module("socket"))
            {
                String hostname = (String)r_module.gethostname();               // get remote hostname
                Console.WriteLine("hostname=" + hostname);
            }

            int sum = (int)flame.evaluate("9+9");

            Console.WriteLine("sum=" + sum);

            flame.execute("import sys; sys.stdout.write('HELLO FROM C#\\n')");

            using (FlameRemoteConsole console = (FlameRemoteConsole)flame.console())
            {
                console.interact();
            }
        }
Example #6
0
	public void testPickleUnpickleProxy() {
		PyroProxy proxy=new PyroProxy("hostname",9999,"objectid");
		Pickler p=new Pickler();
		byte[] pickled_proxy=p.dumps(proxy);
		object result=U(pickled_proxy);
		Assert.IsInstanceOfType(typeof(System.Collections.Hashtable), result); // proxy objects cannot be properly pickled and are pickled as bean, hence HashMap
	}
        public void UnserpentProxy()
        {
            byte[] data = Encoding.UTF8.GetBytes("# serpent utf-8 python3.2\n" +
                                                 "{'state':('PYRO:Pyro.NameServer@localhost:9090',(),('count','lookup','register','ping','list','remove'),(),0.0,'b64:c2VjcmV0','hello',0),'__class__':'Pyro4.core.Proxy'}");

            SerpentSerializer ser = new SerpentSerializer();
            PyroProxy         p   = (PyroProxy)ser.deserializeData(data);

            Assert.IsNull(p.correlation_id);
            Assert.AreEqual("Pyro.NameServer", p.objectid);
            Assert.AreEqual("localhost", p.hostname);
            Assert.AreEqual(9090, p.port);
            Assert.AreEqual("hello", p.pyroHandshake);
            Assert.AreEqual(Encoding.UTF8.GetBytes("secret"), p.pyroHmacKey);
            Assert.AreEqual(0, p.pyroAttrs.Count);
            Assert.AreEqual(0, p.pyroOneway.Count);
            Assert.AreEqual(6, p.pyroMethods.Count);
            ISet <string> methods = new HashSet <string>();

            methods.Add("ping");
            methods.Add("count");
            methods.Add("lookup");
            methods.Add("list");
            methods.Add("register");
            methods.Add("remove");
            CollectionAssert.AreEquivalent(methods, p.pyroMethods);
        }
Example #8
0
        public void PyroClasses()
        {
            var uri = new PyroURI("PYRO:object@host:4444");

            byte[] s = this.ser.serializeData(uri);
            object x = this.ser.deserializeData(s);

            Assert.AreEqual(uri, x);

            var proxy = new PyroProxy(uri);

            s = this.ser.serializeData(proxy);
            x = this.ser.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy)x;

            Assert.AreEqual(uri.host, proxy2.hostname);
            Assert.AreEqual(uri.objectid, proxy2.objectid);
            Assert.AreEqual(uri.port, proxy2.port);

            var ex = new PyroException("error");

            ex._pyroTraceback = "traceback";
            s = this.ser.serializeData(ex);
            x = this.ser.deserializeData(s);
            PyroException ex2 = (PyroException)x;

            Assert.AreEqual(ex.Message, ex2.Message);
            Assert.AreEqual("traceback", ex2._pyroTraceback);
        }
Example #9
0
        private static void UnpickleRealProxy(byte[] pickledProxy)
        {
            PyroSerializer ser   = new PickleSerializer();
            PyroProxy      proxy = (PyroProxy)ser.deserializeData(pickledProxy);

            Assert.Equal("Pyro.NameServer", proxy.objectid);
            Assert.Equal("localhost", proxy.hostname);
            Assert.Equal(9090, proxy.port);
            Assert.Equal("hello", proxy.pyroHandshake);
            Assert.Equal(Encoding.UTF8.GetBytes("secret"), proxy.pyroHmacKey);
            ISet <string> expectedSet = new HashSet <string>();

            Assert.Equal(expectedSet, proxy.pyroAttrs);
            expectedSet.Clear();
            expectedSet.Add("lookup");
            expectedSet.Add("ping");
            expectedSet.Add("register");
            expectedSet.Add("remove");
            expectedSet.Add("list");
            expectedSet.Add("count");
            expectedSet.Add("set_metadata");
            proxy.pyroMethods.ExceptWith(expectedSet);
            Assert.Equal(0, proxy.pyroMethods.Count);     // "something is wrong with the expected exposed methods"
            expectedSet = new HashSet <string>();
            Assert.Equal(expectedSet, proxy.pyroOneway);
        }
Example #10
0
        public void Init()
        {
            _ns         = NameServerProxy.locateNS(null);
            _testserver = new PyroProxy(_ns.lookup("mxnet.csharp.testserver"));

            Serializer.RegisterClass(typeof(Parameter <float>), Parameter <float> .Convert);
        }
Example #11
0
        public static object FromSerpentDict(IDictionary dict)
        {
            // note: the state array received in the dict conforms to the list produced by Pyro's Proxy.__getstate_for_dict__
            // that means, we must get an array of length 8:  (the same as with ToSerpentDict above!)
            // uri, oneway set, methods set, attrs set, timeout, handshake, maxretries  (in this order)
            var     state = (object[])dict["state"];
            PyroURI uri   = new PyroURI((string)state[0]);
            var     proxy = new PyroProxy(uri);

            // the following nasty piece of code is similar to _processMetaData from the PyroProxy
            // this is because the three collections can either be an array or a set
            var onewayArray  = state[1] as object[];
            var methodsArray = state[2] as object[];
            var attrsArray   = state[3] as object[];

            if (onewayArray != null)
            {
                proxy.pyroOneway = new HashSet <string>(onewayArray.Select(o => o as string));
            }
            else if (state[1] is HashSet <string> )
            {
                proxy.pyroOneway = (HashSet <string>)state[1];
            }
            else
            {
                proxy.pyroOneway = new HashSet <string> ((state[1] as HashSet <object>).Select(o => o.ToString()));
            }

            if (methodsArray != null)
            {
                proxy.pyroMethods = new HashSet <string>(methodsArray.Select(o => o as string));
            }
            else if (state[2] is HashSet <string> )
            {
                proxy.pyroMethods = (HashSet <string>)state[2];
            }
            else
            {
                proxy.pyroMethods = new HashSet <string>((state[2] as HashSet <object>).Select(o => o.ToString()));
            }

            if (attrsArray != null)
            {
                proxy.pyroAttrs = new HashSet <string>(attrsArray.Select(o => o as string));
            }
            else if (state[3] is HashSet <string> )
            {
                proxy.pyroAttrs = (HashSet <string>)state[3];
            }
            else
            {
                proxy.pyroAttrs = new HashSet <string>((state[3] as HashSet <object>).Select(o => o.ToString()));
            }

            proxy.pyroHandshake = state[5];
            // maxretries is not used/supported in pyrolite, so simply ignore it

            return(proxy);
        }
Example #12
0
        public void Run()
        {
            setConfig();
            // Config.SERIALIZER = Config.SerializerType.pickle;

            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);
            Console.Write("Enter stream server URI: ");
            string uri = Console.ReadLine();

            using (dynamic p = new PyroProxy(new PyroURI(uri.Trim()))) {
                Console.WriteLine("LIST:");
                dynamic result = p.list();
                Console.WriteLine(result);
                foreach (int i in result)
                {
                    Console.WriteLine(i);
                }

                Console.WriteLine("ITERATOR:");
                using (result = p.iterator())
                {
                    Console.WriteLine(result);
                    foreach (int i in result)
                    {
                        Console.WriteLine(i);
                    }
                }

                Console.WriteLine("GENERATOR:");
                result = p.generator();
                Console.WriteLine(result);
                foreach (int i in result)
                {
                    Console.WriteLine(i);
                }

                Console.WriteLine("SLOW GENERATOR:");
                using (result = p.slow_generator())
                {
                    foreach (int i in result)
                    {
                        Console.WriteLine(i);
                    }
                }

                Console.WriteLine("STOPPING GENERATOR HALFWAY:");
                using (result = p.generator())
                {
                    IEnumerator enumerator = result.GetEnumerator();
                    enumerator.MoveNext();
                    Console.WriteLine(enumerator.Current);
                    enumerator.MoveNext();
                    Console.WriteLine(enumerator.Current);
                    Console.WriteLine("...stopping...");
                }
            }
        }
Example #13
0
        public static Ball FromPyroProxy(PyroProxy proxy)
        {
            IDictionary values = (IDictionary)proxy.call("asDict");
            int         x      = (int)values["x"];
            int         y      = (int)values["y"];
            int         radius = (int)values["radius"];

            return(new Ball(x, y, radius));
        }
Example #14
0
 private PyroProxy new_playfield()
 {
     using (NameServerProxy ns = NameServerProxy.locateNS(null))
     {
         using (PyroProxy playfield = new PyroProxy(ns.lookup("ping.playfield")))
         {
             return(playfield);
         }
     }
 }
Example #15
0
        public static Block FromPyroProxy(PyroProxy proxy)
        {
            IDictionary values = (IDictionary)proxy.call("asDict");
            int         x      = (int)values["x"];
            int         y      = (int)values["y"];
            int         width  = (int)values["width"];
            int         height = (int)values["height"];

            return(new Block(x, y, width, height));
        }
Example #16
0
        private String connect()
        {
            playfield = new_playfield();
            Object result  = playfield.call("test", "connected");
            string message = (string)result;  // cast to the type that 'pythonmethod' returns

            playfield_panel.Width  = (int)playfield.call("get_width");
            playfield_panel.Height = (int)playfield.call("get_height");
            block     = (PyroProxy)playfield.call("create_block");
            connected = true; // Pyro Proxies are not thread safe
            return(message);
        }
Example #17
0
 public static void Main(string[] args)
 {
     using (NameServerProxy ns = NameServerProxy.locateNS(null))
     {
         using (PyroProxy remoteobject = new PyroProxy(ns.lookup("Your.Pyro.Object")))
         {
             object result  = remoteobject.call("pythonmethod", 42, "hello", new int[] { 1, 2, 3 });
             string message = (string)result;   // cast to the type that 'pythonmethod' returns
             Console.WriteLine("result message=" + message);
         }
     }
 }
Example #18
0
        public void testPickleUnpickleProxy()
        {
            PyroProxy      proxy = new PyroProxy("hostname", 9999, "objectid");
            PyroSerializer ser   = new PickleSerializer();

            byte[]    pickled_proxy = ser.serializeData(proxy);
            PyroProxy result        = (PyroProxy)ser.deserializeData(pickled_proxy);

            Assert.AreEqual(proxy.hostname, result.hostname);
            Assert.AreEqual(proxy.objectid, result.objectid);
            Assert.AreEqual(proxy.port, result.port);
        }
Example #19
0
        public void PyroClassesSerpent()
        {
            var ser = new SerpentSerializer();
            var uri = new PyroURI("PYRO:something@localhost:4444");

            byte[] s = ser.serializeData(uri);
            object x = ser.deserializeData(s);

            Assert.Equal(uri, x);

            var proxy = new PyroProxy(uri)
            {
                correlation_id = Guid.NewGuid(),
                pyroHandshake  = "apples",
                pyroHmacKey    = Encoding.UTF8.GetBytes("secret"),
                pyroAttrs      = new HashSet <string> {
                    "attr1", "attr2"
                }
            };

            s = ser.serializeData(proxy);
            x = ser.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy)x;

            Assert.Equal(uri.host, proxy2.hostname);
            Assert.Equal(uri.objectid, proxy2.objectid);
            Assert.Equal(uri.port, proxy2.port);
            Assert.Null(proxy2.correlation_id);             // "correlation_id is not serialized on the proxy object"
            Assert.Equal(proxy.pyroHandshake, proxy2.pyroHandshake);
            Assert.Equal(proxy.pyroHmacKey, proxy2.pyroHmacKey);
            Assert.Equal(2, proxy2.pyroAttrs.Count);
            Assert.Equal(proxy.pyroAttrs, proxy2.pyroAttrs);

            PyroException ex = new PyroException("error");

            s = ser.serializeData(ex);
            x = ser.deserializeData(s);
            PyroException ex2 = (PyroException)x;

            Assert.Equal("[PyroError] error", ex2.Message);
            Assert.Null(ex._pyroTraceback);

            // try another kind of pyro exception
            s   = Encoding.UTF8.GetBytes("{'attributes':{'tb': 'traceback', '_pyroTraceback': ['line1', 'line2']},'__exception__':True,'args':('hello',42),'__class__':'CommunicationError'}");
            x   = ser.deserializeData(s);
            ex2 = (PyroException)x;
            Assert.Equal("[CommunicationError] hello", ex2.Message);
            Assert.Equal("traceback", ex2.Data["tb"]);
            Assert.Equal("line1line2", ex2._pyroTraceback);
            Assert.Equal("CommunicationError", ex2.PythonExceptionType);
        }
Example #20
0
	public void testUnpickleRealProxy() {
		byte[] pickled_proxy=new byte[]
				{128, 2, 99, 80, 121, 114, 111, 52, 46, 99, 111, 114, 101, 10, 80, 114, 111, 120, 121, 10, 113,
				 0, 41, 129, 113, 1, 40, 99, 80, 121, 114, 111, 52, 46, 99, 111, 114, 101, 10, 85, 82, 73, 10,
				 113, 2, 41, 129, 113, 3, 40, 85, 4, 80, 89, 82, 79, 113, 4, 85, 10, 115, 111, 109, 101, 111,
				 98, 106, 101, 99, 116, 113, 5, 78, 85, 9, 108, 111, 99, 97, 108, 104, 111, 115, 116, 113, 6,
				 77, 15, 39, 116, 113, 7, 98, 99, 95, 95, 98, 117, 105, 108, 116, 105, 110, 95, 95, 10, 115,
				 101, 116, 10, 113, 8, 93, 113, 9, 133, 113, 10, 82, 113, 11, 99, 80, 121, 114, 111, 52, 46,
				 117, 116, 105, 108, 10, 83, 101, 114, 105, 97, 108, 105, 122, 101, 114, 10, 113, 12, 41, 129,
				 113, 13, 125, 113, 14, 98, 71, 0, 0, 0, 0, 0, 0, 0, 0, 116, 113, 15, 98, 46};
		PyroProxy proxy=(PyroProxy)U(pickled_proxy);
		Assert.AreEqual("someobject",proxy.objectid);
		Assert.AreEqual("localhost",proxy.hostname);
		Assert.AreEqual(9999,proxy.port);
	}
    public static void Main(string[] args)
    {
        Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);
        string hostname = (string)args[0];
        int    port     = int.Parse(args[1]);

        using (var flame = new PyroProxy(hostname, port, "Pyro.Flame"))
        {
            dynamic r_module = flame.call("module", "socket");
            Console.WriteLine("hostname=" + r_module.call("gethostname"));

            var console = (FlameRemoteConsole)flame.call("console");
            console.interact();
            console.close();
        }
    }
Example #22
0
        public void TestPickleUnpickleProxy()
        {
            PyroProxy proxy = new PyroProxy("hostname", 9999, "objectid")
            {
                pyroHmacKey   = Encoding.UTF8.GetBytes("secret"),
                pyroHandshake = "apples"
            };
            PyroSerializer ser          = new PickleSerializer();
            var            pickledProxy = ser.serializeData(proxy);
            PyroProxy      result       = (PyroProxy)ser.deserializeData(pickledProxy);

            Assert.Equal(proxy.hostname, result.hostname);
            Assert.Equal(proxy.objectid, result.objectid);
            Assert.Equal(proxy.port, result.port);
            Assert.Equal(Encoding.UTF8.GetBytes("secret"), result.pyroHmacKey);
            Assert.Equal("apples", result.pyroHandshake);
        }
Example #23
0
        public void testProxyCorrelationId()
        {
            PyroProxy p = new PyroProxy(new PyroURI("PYRO:foo@localhost:55555"));

            p.correlation_id = null;
            var ann = p.annotations();

            Assert.AreEqual(0, ann.Count);
            p.correlation_id = Guid.NewGuid();
            ann = p.annotations();
            Assert.AreEqual(1, ann.Count);
            Assert.IsTrue(ann.ContainsKey("CORR"));

            Guid uuid = new Guid(ann["CORR"]);

            Assert.AreEqual(p.correlation_id, uuid);
        }
Example #24
0
        public static void Test()
        {
            Console.WriteLine("Testing Pyro nameserver connection (make sure it's running with a broadcast server)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            setConfig();
            Console.WriteLine("serializer used: {0}", Config.SERIALIZER);
            if (Config.SERIALIZER == Config.SerializerType.serpent)
            {
                Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");
            }

            NameServerProxy ns = NameServerProxy.locateNS(null);

            Console.WriteLine("discovered ns at " + ns.hostname + ":" + ns.port);
            ns.ping();

            Console.WriteLine("objects registered in the name server:");
            IDictionary <string, string> objects = ns.list(null, null);

            foreach (string key in objects.Keys)
            {
                Console.WriteLine(key + " --> " + objects[key]);
            }

            ns.register("java.test", new PyroURI("PYRO:JavaTest@localhost:9999"), false);
            Console.WriteLine("uri=" + ns.lookup("java.test"));
            Console.WriteLine("using a new proxy to call the nameserver.");
            PyroProxy p = new PyroProxy(ns.lookup("Pyro.NameServer"));

            p.call("ping");

            int num_removed = ns.remove(null, "java.", null);

            Console.WriteLine("number of removed entries: {0}", num_removed);

            try {
                Console.WriteLine("uri=" + ns.lookup("java.test"));              // should fail....
            } catch (PyroException x) {
                // ok
                Console.WriteLine("got a PyroException (expected): {0}", x.Message);
            }
        }
Example #25
0
        public void PyroClassesPickle()
        {
            var pickler = new PickleSerializer();
            var uri     = new PyroURI("PYRO:something@localhost:4444");

            byte[] s = pickler.serializeData(uri);
            object x = pickler.deserializeData(s);

            Assert.Equal(uri, x);

            var proxy = new PyroProxy(uri)
            {
                correlation_id = Guid.NewGuid(),
                pyroHandshake  = "apples",
                pyroHmacKey    = Encoding.UTF8.GetBytes("secret"),
                pyroAttrs      = new HashSet <string> {
                    "attr1", "attr2"
                }
            };

            s = pickler.serializeData(proxy);
            x = pickler.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy)x;

            Assert.Equal(uri.host, proxy2.hostname);
            Assert.Equal(uri.objectid, proxy2.objectid);
            Assert.Equal(uri.port, proxy2.port);
            Assert.Null(proxy2.correlation_id);             // "correlation_id is not serialized on the proxy object"
            Assert.Equal(proxy.pyroHandshake, proxy2.pyroHandshake);
            Assert.Equal(proxy.pyroHmacKey, proxy2.pyroHmacKey);
            Assert.Equal(2, proxy2.pyroAttrs.Count);
            Assert.Equal(proxy.pyroAttrs, proxy2.pyroAttrs);

            PyroException ex = new PyroException("error");

            s = pickler.serializeData(ex);
            x = pickler.deserializeData(s);
            PyroException ex2 = (PyroException)x;

            Assert.Equal("[Pyro4.errors.PyroError] error", ex2.Message);
            Assert.Null(ex._pyroTraceback);
        }
Example #26
0
        public static IDictionary ToSerpentDict(object obj)
        {
            // note: the state array returned here must conform to the list consumed by Pyro's Proxy.__setstate_from_dict__
            // that means, we make an array of length 8:
            // uri, oneway set, methods set, attrs set, timeout, handshake, maxretries  (in this order)
            PyroProxy proxy = (PyroProxy)obj;
            var       dict  = new Hashtable();
            string    uri   = $"PYRO:{proxy.objectid}@{proxy.hostname}:{proxy.port}";

            dict["state"] = new [] {
                uri,
                proxy.pyroOneway,
                proxy.pyroMethods,
                proxy.pyroAttrs,
                0.0,
                proxy.pyroHandshake,
                0                  // maxretries is not yet supported/used by pyrolite
            };
            dict["__class__"] = "Pyro5.client.Proxy";
            return(dict);
        }
Example #27
0
        public void TestUnserpentProxy()
        {
            var data = Encoding.UTF8.GetBytes("# serpent utf-8 python3.2\n" +
                                              "{'state':('PYRO:Pyro.NameServer@localhost:9090',(),('count','lookup','register','ping','list','remove'),(),0.0,'hello',0),'__class__':'Pyro5.client.Proxy'}");

            SerpentSerializer ser = new SerpentSerializer();
            PyroProxy         p   = (PyroProxy)ser.deserializeData(data);

            Assert.Null(p.correlation_id);
            Assert.Equal("Pyro.NameServer", p.objectid);
            Assert.Equal("localhost", p.hostname);
            Assert.Equal(9090, p.port);
            Assert.Equal("hello", p.pyroHandshake);
            Assert.Equal(0, p.pyroAttrs.Count);
            Assert.Equal(0, p.pyroOneway.Count);
            Assert.Equal(6, p.pyroMethods.Count);
            var methods = new List <string> {
                "count", "list", "lookup", "ping", "register", "remove"
            };

            Assert.Equal(methods, p.pyroMethods.OrderBy(m => m).ToList());
        }
Example #28
0
        public void TestPyroProxySerpent()
        {
            PyroURI   uri   = new PyroURI("PYRO:something@localhost:4444");
            PyroProxy proxy = new PyroProxy(uri)
            {
                correlation_id = Guid.NewGuid(),
                pyroHandshake  = "apples",
                pyroAttrs      = new HashSet <string> {
                    "attr1", "attr2"
                }
            };
            var data = PyroProxySerpent.ToSerpentDict(proxy);

            Assert.Equal(2, data.Count);
            Assert.Equal("Pyro5.client.Proxy", (string)data["__class__"]);
            Assert.Equal(7, ((object[])data["state"]).Length);

            PyroProxy proxy2 = (PyroProxy)PyroProxySerpent.FromSerpentDict(data);

            Assert.Equal(proxy.objectid, proxy2.objectid);
            Assert.Equal("apples", proxy2.pyroHandshake);
        }
Example #29
0
        public static void Test()
        {
            Console.WriteLine("Testing Pyro echo server (make sure it's running on localhost 9999)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            setConfig();

            PyroProxy p = new PyroProxy("localhost", 9999, "test.echoserver");

            Object x = 42;

            Console.WriteLine("echo param:");
            PrettyPrint.print(x);
            Object result = p.call("echo", x);

            Console.WriteLine("return value:");
            PrettyPrint.print(result);

            String s = "This string is way too long. This string is way too long. This string is way too long. This string is way too long. ";

            s = s + s + s + s + s;
            Console.WriteLine("echo param:");
            PrettyPrint.print(s);
            result = p.call("echo", s);
            Console.WriteLine("return value:");
            PrettyPrint.print(result);

            Console.WriteLine("error test.");
            try {
                result = p.call("error");
            } catch (PyroException e) {
                Console.WriteLine("Pyro Exception (expected)! {0}", e.Message);
                Console.WriteLine("Pyro Exception cause: {0}", e.InnerException);
                Console.WriteLine("Pyro Exception remote traceback:\n>>>\n{0}<<<", e._pyroTraceback);
            }

            Console.WriteLine("shutting down the test echo server.");
            p.call("shutdown");
        }
Example #30
0
        public void PyroProxySerpent()
        {
            PyroURI   uri   = new PyroURI("PYRO:something@localhost:4444");
            PyroProxy proxy = new PyroProxy(uri);

            proxy.correlation_id = Guid.NewGuid();
            proxy.pyroHandshake  = "apples";
            proxy.pyroHmacKey    = Encoding.UTF8.GetBytes("secret");
            proxy.pyroAttrs      = new HashSet <string>();
            proxy.pyroAttrs.Add("attr1");
            proxy.pyroAttrs.Add("attr2");
            var data = PyroProxyPickler.ToSerpentDict(proxy);

            Assert.AreEqual(2, data.Count);
            Assert.AreEqual("Pyro4.core.Proxy", data["__class__"]);
            Assert.AreEqual(8, ((object[])data["state"]).Length);

            PyroProxy proxy2 = (PyroProxy)PyroProxyPickler.FromSerpentDict(data);

            Assert.AreEqual(proxy.objectid, proxy2.objectid);
            Assert.AreEqual("apples", proxy2.pyroHandshake);
        }