Esempio n. 1
0
    public static int Main(string[] args)
    {
        int status = 0;

        Ice.Communicator communicator = null;

        try
        {
            Console.Error.Write("testing proxy & endpoint hash algorithm collisions... ");
            Console.Error.Flush();
            Dictionary <int, Ice.ObjectPrx> seenProxy    = new Dictionary <int, Ice.ObjectPrx>();
            Dictionary <int, Ice.Endpoint>  seenEndpoint = new Dictionary <int, Ice.Endpoint>();
            int proxyCollisions    = 0;
            int endpointCollisions = 0;
            int i             = 0;
            int maxCollisions = 10;
            int maxIterations = 10000;

            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = Ice.Util.createProperties(ref args);
            //initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL:IceSSL.PluginFactory");
            communicator = Ice.Util.initialize(ref args, initData);
            {
                Random rand = new Random();
                for (i = 0; proxyCollisions < maxCollisions &&
                     endpointCollisions < maxCollisions &&
                     i < maxIterations; ++i)
                {
                    System.IO.StringWriter sw = new System.IO.StringWriter();
                    sw.Write(i);
                    sw.Write(":tcp -p ");
                    sw.Write(rand.Next(65536));
                    sw.Write(" -t 10");
                    sw.Write(rand.Next(1000000));
                    sw.Write(":udp -p ");
                    sw.Write(rand.Next(65536));
                    sw.Write(" -h ");
                    sw.Write(rand.Next(100));

                    Ice.ObjectPrx       obj       = communicator.stringToProxy(sw.ToString());
                    List <Ice.Endpoint> endpoints = new List <Ice.Endpoint>(obj.ice_getEndpoints());

                    if (seenProxy.ContainsKey(obj.GetHashCode()))
                    {
                        if (obj.Equals(seenProxy[obj.GetHashCode()]))
                        {
                            continue;
                        }
                        ++proxyCollisions;
                    }
                    else
                    {
                        seenProxy[obj.GetHashCode()] = obj;
                    }

                    foreach (Ice.Endpoint endpoint in endpoints)
                    {
                        if (seenEndpoint.ContainsKey(endpoint.GetHashCode()))
                        {
                            if (endpoint.Equals(seenEndpoint[endpoint.GetHashCode()]))
                            {
                                continue;
                            }
                            ++endpointCollisions;
                        }
                        else
                        {
                            seenEndpoint[endpoint.GetHashCode()] = endpoint;
                        }
                        //
                        // Check the same endpoint produce always the same hash
                        //
                        test(endpoint.GetHashCode() == endpoint.GetHashCode());
                    }
                    //
                    // Check the same proxy produce always the same hash
                    //
                    test(obj.GetHashCode() == obj.GetHashCode());
                }
                test(proxyCollisions < maxCollisions);
                test(endpointCollisions < maxCollisions);
                {
                    Ice.ProxyIdentityKey comparer = new Ice.ProxyIdentityKey();
                    proxyCollisions = 0;
                    seenProxy       = new Dictionary <int, Ice.ObjectPrx>();
                    for (i = 0; proxyCollisions < maxCollisions && i < maxIterations; ++i)
                    {
                        System.IO.StringWriter sw = new System.IO.StringWriter();
                        sw.Write(i);
                        sw.Write(":tcp -p ");
                        sw.Write(rand.Next(65536));
                        sw.Write(" -t 10");
                        sw.Write(rand.Next(1000000));
                        sw.Write(":udp -p ");
                        sw.Write(rand.Next(65536));
                        sw.Write(" -h ");
                        sw.Write(rand.Next(100));

                        Ice.ObjectPrx obj = communicator.stringToProxy(sw.ToString());

                        if (seenProxy.ContainsKey(comparer.GetHashCode(obj)))
                        {
                            ++proxyCollisions;
                        }
                        else
                        {
                            seenProxy[comparer.GetHashCode(obj)] = obj;
                        }
                        //
                        // Check the same proxy produce always the same hash
                        //
                        test(comparer.GetHashCode(obj) == comparer.GetHashCode(obj));
                    }
                    test(proxyCollisions < maxCollisions);
                }
            }

            {
                Random rand = new Random();
                Ice.ProxyIdentityFacetKey comparer = new Ice.ProxyIdentityFacetKey();
                proxyCollisions = 0;
                seenProxy       = new Dictionary <int, Ice.ObjectPrx>();
                for (i = 0; proxyCollisions < maxCollisions && i < maxIterations; ++i)
                {
                    System.IO.StringWriter sw = new System.IO.StringWriter();
                    sw.Write(i);
                    sw.Write(" -f demo:tcp -p ");
                    sw.Write(rand.Next(65536));
                    sw.Write(" -t 10");
                    sw.Write(rand.Next(1000000));
                    sw.Write(":udp -p ");
                    sw.Write(rand.Next(65536));
                    sw.Write(" -h ");
                    sw.Write(rand.Next(100));

                    Ice.ObjectPrx obj = communicator.stringToProxy(sw.ToString());

                    if (seenProxy.ContainsKey(comparer.GetHashCode(obj)))
                    {
                        ++proxyCollisions;
                    }
                    else
                    {
                        seenProxy[comparer.GetHashCode(obj)] = obj;
                    }
                    //
                    // Check the same proxy produce always the same hash
                    //
                    test(comparer.GetHashCode(obj) == comparer.GetHashCode(obj));
                }
                test(proxyCollisions < maxCollisions);
            }

            Ice.ProxyIdentityFacetKey iComparer  = new Ice.ProxyIdentityFacetKey();
            Ice.ProxyIdentityFacetKey ifComparer = new Ice.ProxyIdentityFacetKey();

            Ice.ObjectPrx prx1 = communicator.stringToProxy("Glacier2/router:tcp -p 10010");
            //Ice.ObjectPrx prx2 = communicator.stringToProxy("Glacier2/router:ssl -p 10011");
            Ice.ObjectPrx prx3 = communicator.stringToProxy("Glacier2/router:udp -p 10012");
            Ice.ObjectPrx prx4 = communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010");
            //Ice.ObjectPrx prx5 = communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011");
            Ice.ObjectPrx prx6 = communicator.stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012");
            Ice.ObjectPrx prx7 = communicator.stringToProxy("Glacier2/router:tcp -p 10010 -t 10000");
            //Ice.ObjectPrx prx8 = communicator.stringToProxy("Glacier2/router:ssl -p 10011 -t 10000");
            Ice.ObjectPrx prx9 = communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000");
            //Ice.ObjectPrx prx10 = communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000");

            Dictionary <string, int> proxyMap = new Dictionary <string, int>();
            proxyMap["prx1"] = prx1.GetHashCode();
            //proxyMap["prx2"] = prx2.GetHashCode();
            proxyMap["prx3"] = prx3.GetHashCode();
            proxyMap["prx4"] = prx4.GetHashCode();
            //proxyMap["prx5"] = prx5.GetHashCode();
            proxyMap["prx6"] = prx6.GetHashCode();
            proxyMap["prx7"] = prx7.GetHashCode();
            //proxyMap["prx8"] = prx8.GetHashCode();
            proxyMap["prx9"] = prx9.GetHashCode();
            //proxyMap["prx10"] = prx10.GetHashCode();

            test(communicator.stringToProxy("Glacier2/router:tcp -p 10010").GetHashCode() == proxyMap["prx1"]);
            //test(communicator.stringToProxy("Glacier2/router:ssl -p 10011").GetHashCode() == proxyMap["prx2"]);
            test(communicator.stringToProxy("Glacier2/router:udp -p 10012").GetHashCode() == proxyMap["prx3"]);
            test(communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010").GetHashCode() == proxyMap["prx4"]);
            //test(communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011").GetHashCode() == proxyMap["prx5"]);
            test(communicator.stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012").GetHashCode() == proxyMap["prx6"]);
            test(communicator.stringToProxy("Glacier2/router:tcp -p 10010 -t 10000").GetHashCode() == proxyMap["prx7"]);
            //test(communicator.stringToProxy("Glacier2/router:ssl -p 10011 -t 10000").GetHashCode() == proxyMap["prx8"]);
            test(communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000").GetHashCode() == proxyMap["prx9"]);
            //test(communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000").GetHashCode() == proxyMap["prx10"]);

            test(iComparer.GetHashCode(prx1) == iComparer.GetHashCode(prx1));
            test(ifComparer.GetHashCode(prx1) == ifComparer.GetHashCode(prx1));

            test(iComparer.GetHashCode(prx3) == iComparer.GetHashCode(prx3));
            test(ifComparer.GetHashCode(prx3) == ifComparer.GetHashCode(prx3));

            test(iComparer.GetHashCode(prx4) == iComparer.GetHashCode(prx4));
            test(ifComparer.GetHashCode(prx4) == ifComparer.GetHashCode(prx4));

            test(iComparer.GetHashCode(prx6) == iComparer.GetHashCode(prx6));
            test(ifComparer.GetHashCode(prx6) == ifComparer.GetHashCode(prx6));

            test(iComparer.GetHashCode(prx7) == iComparer.GetHashCode(prx7));
            test(ifComparer.GetHashCode(prx7) == ifComparer.GetHashCode(prx7));

            test(iComparer.GetHashCode(prx9) == iComparer.GetHashCode(prx9));
            test(ifComparer.GetHashCode(prx9) == ifComparer.GetHashCode(prx9));

            Console.Error.WriteLine("ok");

            Console.Error.Write("testing exceptions hash algorithm collisions... ");

            {
                Dictionary <int, Test.OtherException> seenException = new Dictionary <int, Test.OtherException>();
                Random rand = new Random();

                int exceptionCollisions = 0;
                for (i = 0; i < maxIterations &&
                     exceptionCollisions < maxCollisions; ++i)
                {
                    Test.OtherException ex = new Test.OtherException(rand.Next(100), rand.Next(100), 0, false);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }
                    //
                    // Check the same exception produce always the same hash
                    //
                    test(ex.GetHashCode() == ex.GetHashCode());
                }
                test(exceptionCollisions < maxCollisions);
            }

            //
            // Same as above but with numbers in high ranges
            //
            {
                Dictionary <int, Test.OtherException> seenException = new Dictionary <int, Test.OtherException>();
                Random rand = new Random();

                int exceptionCollisions = 0;
                for (i = 0; i < maxIterations &&
                     exceptionCollisions < maxCollisions; ++i)
                {
                    Test.OtherException ex = new Test.OtherException(rand.Next(100) * 2 ^ 30, rand.Next(100) * 2 ^ 30, rand.Next(100) * 2 ^ 30, false);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }
                    //
                    // Check the same exception produce always the same hash
                    //
                    test(ex.GetHashCode() == ex.GetHashCode());
                }
                test(exceptionCollisions < maxCollisions);
            }

            {
                Dictionary <int, Test.BaseException> seenException = new Dictionary <int, Test.BaseException>();
                Random rand = new Random();

                int exceptionCollisions = 0;
                for (i = 0; i < maxIterations &&
                     exceptionCollisions < maxCollisions; ++i)
                {
                    int v = rand.Next(1000);
                    Test.BaseException ex = new Test.InvalidPointException(v);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }

                    //
                    // Check the same exception produce always the same hash
                    //
                    test(ex.GetHashCode() == ex.GetHashCode());

                    ex = new Test.InvalidLengthException(v);
                    if (seenException.ContainsKey(ex.GetHashCode()))
                    {
                        if (ex.Equals(seenException[ex.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        exceptionCollisions++;
                    }
                    else
                    {
                        seenException[ex.GetHashCode()] = ex;
                    }

                    //
                    // Check the same exception produce always the same hash
                    //
                    test(ex.GetHashCode() == ex.GetHashCode());
                }
                test(exceptionCollisions < maxCollisions);
            }
            Console.Error.WriteLine("ok");

            Console.Error.Write("testing struct hash algorithm collisions... ");
            {
                Dictionary <int, Test.PointF> seenPointF = new Dictionary <int, Test.PointF>();
                Random rand             = new Random();
                int    structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.PointF pf = new Test.PointF((float)rand.NextDouble(), (float)rand.NextDouble(),
                                                     (float)rand.NextDouble());
                    if (seenPointF.ContainsKey(pf.GetHashCode()))
                    {
                        if (pf.Equals(seenPointF[pf.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenPointF[pf.GetHashCode()] = pf;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(pf.GetHashCode() == pf.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                Dictionary <int, Test.PointD> seenPointD = new Dictionary <int, Test.PointD>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.PointD pd = new Test.PointD(rand.NextDouble(), rand.NextDouble(),
                                                     rand.NextDouble());
                    if (seenPointD.ContainsKey(pd.GetHashCode()))
                    {
                        if (pd.Equals(seenPointD[pd.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenPointD[pd.GetHashCode()] = pd;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(pd.GetHashCode() == pd.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                Dictionary <int, Test.Polyline> seenPolyline = new Dictionary <int, Test.Polyline>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.Polyline     polyline = new Test.Polyline();
                    List <Test.Point> vertices = new List <Test.Point>();
                    for (int j = 0; j < 100; ++j)
                    {
                        vertices.Add(new Test.Point(rand.Next(100), rand.Next(100)));
                    }
                    polyline.vertices = vertices.ToArray();

                    if (seenPolyline.ContainsKey(polyline.GetHashCode()))
                    {
                        if (polyline.Equals(seenPolyline[polyline.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenPolyline[polyline.GetHashCode()] = polyline;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(polyline.GetHashCode() == polyline.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                Dictionary <int, Test.ColorPalette> seenColorPalette = new Dictionary <int, Test.ColorPalette>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.ColorPalette colorPalette = new Test.ColorPalette();
                    colorPalette.colors = new Dictionary <int, Test.Color>();
                    for (int j = 0; j < 100; ++j)
                    {
                        colorPalette.colors[j] = new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255));
                    }

                    if (seenColorPalette.ContainsKey(colorPalette.GetHashCode()))
                    {
                        if (colorPalette.Equals(seenColorPalette[colorPalette.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenColorPalette[colorPalette.GetHashCode()] = colorPalette;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(colorPalette.GetHashCode() == colorPalette.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                Dictionary <int, Test.Color> seenColor = new Dictionary <int, Test.Color>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.Color c = new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255));
                    if (seenColor.ContainsKey(c.GetHashCode()))
                    {
                        if (c.Equals(seenColor[c.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenColor[c.GetHashCode()] = c;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(c.GetHashCode() == c.GetHashCode());
                }
                test(structCollisions < maxCollisions);

                structCollisions = 0;
                Dictionary <int, Test.Draw> seenDraw = new Dictionary <int, Test.Draw>();
                structCollisions = 0;
                for (i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
                {
                    Test.Draw draw = new Test.Draw(
                        new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)),
                        new Test.Pen(rand.Next(10),
                                     new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))),
                        false);

                    if (seenDraw.ContainsKey(draw.GetHashCode()))
                    {
                        if (draw.Equals(seenDraw[draw.GetHashCode()]))
                        {
                            continue; // same object
                        }
                        structCollisions++;
                    }
                    else
                    {
                        seenDraw[draw.GetHashCode()] = draw;
                    }
                    //
                    // Check the same struct produce always the same hash
                    //
                    test(draw.GetHashCode() == draw.GetHashCode());
                }
                test(structCollisions < maxCollisions);
            }
            Console.Error.WriteLine("ok");

            if (communicator != null)
            {
                communicator.destroy();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
            status = 1;
        }

        return(status);
    }
Esempio n. 2
0
            public static Test.TestIntfPrx allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                var output = helper.getWriter();

                output.Write("testing stringToProxy... ");
                output.Flush();
                string @ref = "test:" + helper.getTestEndpoint(0);

                Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
                test(@base != null);
                output.WriteLine("ok");

                output.Write("testing checked cast... ");
                output.Flush();
                var obj = Test.TestIntfPrxHelper.checkedCast(@base);

                test(obj != null);
                test(obj.Equals(@base));
                output.WriteLine("ok");

                {
                    output.Write("creating/destroying/recreating object adapter... ");
                    output.Flush();
                    Ice.ObjectAdapter adapter =
                        communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                    try
                    {
                        communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                        test(false);
                    }
                    catch (Ice.AlreadyRegisteredException)
                    {
                    }
                    adapter.destroy();

                    //
                    // Use a different port than the first adapter to avoid an "address already in use" error.
                    //
                    adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                    adapter.destroy();
                    output.WriteLine("ok");
                }

                output.Write("creating/activating/deactivating object adapter in one operation... ");
                output.Flush();
                obj.transient();
                obj.end_transient(obj.begin_transient());
                output.WriteLine("ok");

                {
                    output.Write("testing connection closure... ");
                    output.Flush();
                    for (int i = 0; i < 10; ++i)
                    {
                        Ice.InitializationData initData = new Ice.InitializationData();
                        initData.properties = communicator.getProperties().ice_clone_();
                        Ice.Communicator comm = Ice.Util.initialize(initData);
                        comm.stringToProxy("test:" + helper.getTestEndpoint(0)).begin_ice_ping();
                        comm.destroy();
                    }
                    output.WriteLine("ok");
                }

                output.Write("testing object adapter published endpoints... ");
                output.Flush();
                {
                    communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000");
                    Ice.ObjectAdapter adapter = communicator.createObjectAdapter("PAdapter");
                    test(adapter.getPublishedEndpoints().Length == 1);
                    Ice.Endpoint endpt = adapter.getPublishedEndpoints()[0];
                    test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000"));
                    Ice.ObjectPrx prx =
                        communicator.stringToProxy("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000");
                    adapter.setPublishedEndpoints(prx.ice_getEndpoints());
                    test(adapter.getPublishedEndpoints().Length == 2);
                    Ice.Identity id = new Ice.Identity();
                    id.name = "dummy";
                    test(IceUtilInternal.Arrays.Equals(adapter.createProxy(id).ice_getEndpoints(), prx.ice_getEndpoints()));
                    test(IceUtilInternal.Arrays.Equals(adapter.getPublishedEndpoints(), prx.ice_getEndpoints()));
                    adapter.refreshPublishedEndpoints();
                    test(adapter.getPublishedEndpoints().Length == 1);
                    test(adapter.getPublishedEndpoints()[0].Equals(endpt));
                    communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000");
                    adapter.refreshPublishedEndpoints();
                    test(adapter.getPublishedEndpoints().Length == 1);
                    test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 12345 -t 20000"));
                    adapter.destroy();
                    test(adapter.getPublishedEndpoints().Length == 0);
                }
                output.WriteLine("ok");

                if (obj.ice_getConnection() != null)
                {
                    output.Write("testing object adapter with bi-dir connection... ");
                    output.Flush();
                    Ice.ObjectAdapter adapter = communicator.createObjectAdapter("");
                    obj.ice_getConnection().setAdapter(adapter);
                    obj.ice_getConnection().setAdapter(null);
                    adapter.deactivate();
                    try
                    {
                        obj.ice_getConnection().setAdapter(adapter);
                        test(false);
                    }
                    catch (Ice.ObjectAdapterDeactivatedException)
                    {
                    }
                    output.WriteLine("ok");
                }

                output.Write("testing object adapter with router... ");
                output.Flush();
                {
                    Ice.Identity routerId = new Ice.Identity();
                    routerId.name = "router";
                    Ice.RouterPrx router =
                        Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId).ice_connectionId("rc"));
                    Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithRouter("", router);
                    test(adapter.getPublishedEndpoints().Length == 1);
                    test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23456 -t 30000"));
                    adapter.refreshPublishedEndpoints();
                    test(adapter.getPublishedEndpoints().Length == 1);
                    test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23457 -t 30000"));
                    try
                    {
                        adapter.setPublishedEndpoints(router.ice_getEndpoints());
                        test(false);
                    }
                    catch (ArgumentException)
                    {
                        // Expected.
                    }
                    adapter.destroy();

                    try
                    {
                        routerId.name = "test";
                        router        = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId));
                        communicator.createObjectAdapterWithRouter("", router);
                        test(false);
                    }
                    catch (Ice.OperationNotExistException)
                    {
                        // Expected: the "test" object doesn't implement Ice::Router!
                    }

                    try
                    {
                        router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("test:" +
                                                                                              helper.getTestEndpoint(1)));
                        communicator.createObjectAdapterWithRouter("", router);
                        test(false);
                    }
                    catch (Ice.ConnectFailedException)
                    {
                    }
                }
                output.WriteLine("ok");

                output.Write("testing object adapter creation with port in use... ");
                output.Flush();
                {
                    var adapter1 = communicator.createObjectAdapterWithEndpoints("Adpt1", helper.getTestEndpoint(10));
                    try
                    {
                        communicator.createObjectAdapterWithEndpoints("Adpt2", helper.getTestEndpoint(10));
                        test(false);
                    }
                    catch (Ice.LocalException)
                    {
                        // Expected can't re-use the same endpoint.
                    }
                    adapter1.destroy();
                }
                output.WriteLine("ok");

                output.Write("deactivating object adapter in the server... ");
                output.Flush();
                obj.deactivate();
                output.WriteLine("ok");

                output.Write("testing whether server is gone... ");
                output.Flush();
                try
                {
                    obj.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows
                    test(false);
                }
                catch (Ice.LocalException)
                {
                    output.WriteLine("ok");
                }

                return(obj);
            }
Esempio n. 3
0
    public static void allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        Write("testing proxy endpoint information... ");
        Flush();
        {
            Ice.ObjectPrx p1 = communicator.stringToProxy(
                "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" +
                "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" +
                "opaque -e 1.8 -t 100 -v ABCD");

            Ice.Endpoint[] endps = p1.ice_getEndpoints();

            Ice.EndpointInfo    info        = endps[0].getInfo();
            Ice.TCPEndpointInfo tcpEndpoint = getTCPEndpointInfo(info);
            test(tcpEndpoint.host.Equals("tcphost"));
            test(tcpEndpoint.port == 10000);
            test(tcpEndpoint.sourceAddress.Equals("10.10.10.10"));
            test(tcpEndpoint.timeout == 1200);
            test(tcpEndpoint.compress);
            test(!tcpEndpoint.datagram());

            test(tcpEndpoint.type() == Ice.TCPEndpointType.value && !tcpEndpoint.secure() ||
                 tcpEndpoint.type() == Ice.SSLEndpointType.value && tcpEndpoint.secure() ||
                 tcpEndpoint.type() == Ice.WSEndpointType.value && !tcpEndpoint.secure() ||
                 tcpEndpoint.type() == Ice.WSSEndpointType.value && tcpEndpoint.secure());
            test(tcpEndpoint.type() == Ice.TCPEndpointType.value && info is Ice.TCPEndpointInfo ||
                 tcpEndpoint.type() == Ice.SSLEndpointType.value && info is IceSSL.EndpointInfo ||
                 tcpEndpoint.type() == Ice.WSEndpointType.value && info is Ice.WSEndpointInfo ||
                 tcpEndpoint.type() == Ice.WSSEndpointType.value && info is Ice.WSEndpointInfo);

            Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endps[1].getInfo();
            test(udpEndpoint.host.Equals("udphost"));
            test(udpEndpoint.port == 10001);
            test(udpEndpoint.mcastInterface.Equals("eth0"));
            test(udpEndpoint.mcastTtl == 5);
            test(udpEndpoint.sourceAddress.Equals("10.10.10.10"));
            test(udpEndpoint.timeout == -1);
            test(!udpEndpoint.compress);
            test(!udpEndpoint.secure());
            test(udpEndpoint.datagram());
            test(udpEndpoint.type() == 3);

            Ice.OpaqueEndpointInfo opaqueEndpoint = (Ice.OpaqueEndpointInfo)endps[2].getInfo();
            test(opaqueEndpoint.rawBytes.Length > 0);
            test(opaqueEndpoint.rawEncoding.Equals(new Ice.EncodingVersion(1, 8)));
        }
        WriteLine("ok");

        Ice.ObjectAdapter adapter;
        Write("test object adapter endpoint information... ");
        Flush();
        {
            string host = communicator.getProperties().getPropertyAsInt("Ice.IPv6") != 0 ? "::1" : "127.0.0.1";
            communicator.getProperties().setProperty("TestAdapter.Endpoints", "tcp -h \"" + host +
                                                     "\" -t 15000:udp -h \"" + host + "\"");
            adapter = communicator.createObjectAdapter("TestAdapter");

            Ice.Endpoint[] endpoints = adapter.getEndpoints();
            test(endpoints.Length == 2);
            Ice.Endpoint[] publishedEndpoints = adapter.getPublishedEndpoints();
            test(IceUtilInternal.Arrays.Equals(endpoints, publishedEndpoints));

            Ice.TCPEndpointInfo tcpEndpoint = getTCPEndpointInfo(endpoints[0].getInfo());
            test(tcpEndpoint.type() == Ice.TCPEndpointType.value || tcpEndpoint.type() == Ice.SSLEndpointType.value ||
                 tcpEndpoint.type() == Ice.WSEndpointType.value || tcpEndpoint.type() == Ice.WSSEndpointType.value);

            test(tcpEndpoint.host.Equals(host));
            test(tcpEndpoint.port > 0);
            test(tcpEndpoint.timeout == 15000);

            Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endpoints[1].getInfo();
            test(udpEndpoint.host.Equals(host));
            test(udpEndpoint.datagram());
            test(udpEndpoint.port > 0);

            endpoints = new Ice.Endpoint[] { endpoints[0] };
            test(endpoints.Length == 1);
            adapter.setPublishedEndpoints(endpoints);
            publishedEndpoints = adapter.getPublishedEndpoints();
            test(IceUtilInternal.Arrays.Equals(endpoints, publishedEndpoints));

            adapter.destroy();

            int port = app.getTestPort(1);
            communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -h * -p " + port);
            communicator.getProperties().setProperty("TestAdapter.PublishedEndpoints", app.getTestEndpoint(1));
            adapter = communicator.createObjectAdapter("TestAdapter");

            endpoints = adapter.getEndpoints();
            test(endpoints.Length >= 1);
            publishedEndpoints = adapter.getPublishedEndpoints();
            test(publishedEndpoints.Length == 1);

            foreach (Ice.Endpoint endpoint in endpoints)
            {
                tcpEndpoint = getTCPEndpointInfo(endpoint.getInfo());
                test(tcpEndpoint.port == port);
            }

            tcpEndpoint = getTCPEndpointInfo(publishedEndpoints[0].getInfo());
            test(tcpEndpoint.host.Equals("127.0.0.1"));
            test(tcpEndpoint.port == port);

            adapter.destroy();
        }
        WriteLine("ok");

        int endpointPort = app.getTestPort(0);

        Ice.ObjectPrx @base = communicator.stringToProxy("test:" +
                                                         app.getTestEndpoint(0) + ":" +
                                                         app.getTestEndpoint(0, "udp"));
        TestIntfPrx testIntf = TestIntfPrxHelper.checkedCast(@base);

        string defaultHost = communicator.getProperties().getProperty("Ice.Default.Host");

        Write("test connection endpoint information... ");
        Flush();
        {
            Ice.EndpointInfo    info    = @base.ice_getConnection().getEndpoint().getInfo();
            Ice.TCPEndpointInfo tcpinfo = getTCPEndpointInfo(info);
            test(tcpinfo.port == endpointPort);
            test(!tcpinfo.compress);
            test(tcpinfo.host.Equals(defaultHost));

            Dictionary <string, string> ctx = testIntf.getEndpointInfoAsContext();
            test(ctx["host"].Equals(tcpinfo.host));
            test(ctx["compress"].Equals("false"));
            int port = System.Int32.Parse(ctx["port"]);
            test(port > 0);

            info = @base.ice_datagram().ice_getConnection().getEndpoint().getInfo();
            Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)info;
            test(udp.port == endpointPort);
            test(udp.host.Equals(defaultHost));
        }
        WriteLine("ok");

        Write("testing connection information... ");
        Flush();
        {
            Ice.Connection connection = @base.ice_getConnection();
            connection.setBufferSize(1024, 2048);

            Ice.ConnectionInfo    info   = connection.getInfo();
            Ice.TCPConnectionInfo ipInfo = getTCPConnectionInfo(info);
            test(!info.incoming);
            test(info.adapterName.Length == 0);
            test(ipInfo.remotePort == endpointPort);
            test(ipInfo.localPort > 0);
            if (defaultHost.Equals("127.0.0.1"))
            {
                test(ipInfo.localAddress.Equals(defaultHost));
                test(ipInfo.remoteAddress.Equals(defaultHost));
            }
            test(ipInfo.rcvSize >= 1024);
            test(ipInfo.sndSize >= 2048);

            Dictionary <string, string> ctx = testIntf.getConnectionInfoAsContext();
            test(ctx["incoming"].Equals("true"));
            test(ctx["adapterName"].Equals("TestAdapter"));
            test(ctx["remoteAddress"].Equals(ipInfo.localAddress));
            test(ctx["localAddress"].Equals(ipInfo.remoteAddress));
            test(ctx["remotePort"].Equals(ipInfo.localPort.ToString()));
            test(ctx["localPort"].Equals(ipInfo.remotePort.ToString()));

            if (@base.ice_getConnection().type().Equals("ws") || @base.ice_getConnection().type().Equals("wss"))
            {
                Dictionary <string, string> headers = ((Ice.WSConnectionInfo)info).headers;
                test(headers["Upgrade"].Equals("websocket"));
                test(headers["Connection"].Equals("Upgrade"));
                test(headers["Sec-WebSocket-Protocol"].Equals("ice.zeroc.com"));
                test(headers["Sec-WebSocket-Accept"] != null);

                test(ctx["ws.Upgrade"].Equals("websocket"));
                test(ctx["ws.Connection"].Equals("Upgrade"));
                test(ctx["ws.Sec-WebSocket-Protocol"].Equals("ice.zeroc.com"));
                test(ctx["ws.Sec-WebSocket-Version"].Equals("13"));
                test(ctx["ws.Sec-WebSocket-Key"] != null);
            }

            connection = @base.ice_datagram().ice_getConnection();
            connection.setBufferSize(2048, 1024);

            Ice.UDPConnectionInfo udpInfo = (Ice.UDPConnectionInfo)connection.getInfo();
            test(!udpInfo.incoming);
            test(udpInfo.adapterName.Length == 0);
            test(udpInfo.localPort > 0);
            test(udpInfo.remotePort == endpointPort);

            if (defaultHost.Equals("127.0.0.1"))
            {
                test(udpInfo.remoteAddress.Equals(defaultHost));
                test(udpInfo.localAddress.Equals(defaultHost));
            }
            test(udpInfo.rcvSize >= 2048);
            test(udpInfo.sndSize >= 1024);
        }
        WriteLine("ok");

        testIntf.shutdown();

        communicator.shutdown();
        communicator.waitForShutdown();
    }
Esempio n. 4
0
    public static void allTests(Ice.Communicator communicator)
#endif
    {
        Write("testing proxy endpoint information... ");
        Flush();
        {
            Ice.ObjectPrx p1 = communicator.stringToProxy(
                "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" +
                "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" +
                "opaque -e 1.8 -t 100 -v ABCD");

            Ice.Endpoint[] endps = p1.ice_getEndpoints();


            Ice.IPEndpointInfo ipEndpoint = (Ice.IPEndpointInfo)endps[0].getInfo();
            test(ipEndpoint.host.Equals("tcphost"));
            test(ipEndpoint.port == 10000);
            test(ipEndpoint.sourceAddress.Equals("10.10.10.10"));
            test(ipEndpoint.timeout == 1200);
            test(ipEndpoint.compress);
            test(!ipEndpoint.datagram());

#if __MonoCS__
            test(ipEndpoint.type() == Ice.TCPEndpointType.value && !ipEndpoint.secure() ||
                 ipEndpoint.type() == Ice.WSEndpointType.value && !ipEndpoint.secure());
            test(ipEndpoint.type() == Ice.TCPEndpointType.value && ipEndpoint is Ice.TCPEndpointInfo ||
                 ipEndpoint.type() == Ice.WSEndpointType.value && ipEndpoint is Ice.WSEndpointInfo);
#elif COMPACT || SILVERLIGHT
            test(ipEndpoint.type() == Ice.TCPEndpointType.value && !ipEndpoint.secure());
            test(ipEndpoint.type() == Ice.TCPEndpointType.value && ipEndpoint is Ice.TCPEndpointInfo);
#else
            test(ipEndpoint.type() == Ice.TCPEndpointType.value && !ipEndpoint.secure() ||
                 ipEndpoint.type() == IceSSL.EndpointType.value && ipEndpoint.secure() ||
                 ipEndpoint.type() == Ice.WSEndpointType.value && !ipEndpoint.secure() ||
                 ipEndpoint.type() == Ice.WSSEndpointType.value && ipEndpoint.secure());
            test(ipEndpoint.type() == Ice.TCPEndpointType.value && ipEndpoint is Ice.TCPEndpointInfo ||
                 ipEndpoint.type() == IceSSL.EndpointType.value && ipEndpoint is IceSSL.EndpointInfo ||
                 ipEndpoint.type() == Ice.WSEndpointType.value && ipEndpoint is Ice.WSEndpointInfo ||
                 ipEndpoint.type() == Ice.WSSEndpointType.value && ipEndpoint is IceSSL.WSSEndpointInfo);
#endif

            Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endps[1].getInfo();
            test(udpEndpoint.host.Equals("udphost"));
            test(udpEndpoint.port == 10001);
            test(udpEndpoint.mcastInterface.Equals("eth0"));
            test(udpEndpoint.mcastTtl == 5);
            test(udpEndpoint.sourceAddress.Equals("10.10.10.10"));
            test(udpEndpoint.timeout == -1);
            test(!udpEndpoint.compress);
            test(!udpEndpoint.secure());
            test(udpEndpoint.datagram());
            test(udpEndpoint.type() == 3);

            Ice.OpaqueEndpointInfo opaqueEndpoint = (Ice.OpaqueEndpointInfo)endps[2].getInfo();
            test(opaqueEndpoint.rawBytes.Length > 0);
            test(opaqueEndpoint.rawEncoding.Equals(new Ice.EncodingVersion(1, 8)));
        }
        WriteLine("ok");

        string defaultHost = communicator.getProperties().getProperty("Ice.Default.Host");
#if !SILVERLIGHT
        Ice.ObjectAdapter adapter;
        Write("test object adapter endpoint information... ");
        Flush();
        {
            communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -t 15000:udp");
            adapter = communicator.createObjectAdapter("TestAdapter");

            Ice.Endpoint[] endpoints = adapter.getEndpoints();
            test(endpoints.Length == 2);
            Ice.Endpoint[] publishedEndpoints = adapter.getPublishedEndpoints();
            test(IceUtilInternal.Arrays.Equals(endpoints, publishedEndpoints));

            Ice.IPEndpointInfo ipEndpoint = (Ice.IPEndpointInfo)endpoints[0].getInfo();
#  if __MonoCS__
            test(ipEndpoint.type() == Ice.TCPEndpointType.value || ipEndpoint.type() == Ice.WSEndpointType.value);
#  elif COMPACT