Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.9.18
    • Fix Version/s: 2.1
    • Component/s: http
    • Labels:
      None

      Description

      We need to be able to instantiate a new Grizzly instance bound to any available port (as opposed to specifying the port number). This is useful for running unit tests in parallel where each test should get its own dedicated web server and we want to avoid race conditions where ports might become unavailable between the time we look them up and the time Grizzly tries using them.

        Activity

        Hide
        oleksiys added a comment -

        you can try to specify port = 0.
        does it work for you?

        Show
        oleksiys added a comment - you can try to specify port = 0. does it work for you?
        Hide
        cowwoc added a comment -

        It's hard for me to tell whether it's working because I'm accessing Grizzly behind jersey-test. See JERSEY-710 for the related Jersey issue.

        I can set port to 0, but for this to work I need to be able to find out what concrete port Grizzly ended up using. The unit test web client needs to know which port to connect to. Any idea on how to do that?

        Show
        cowwoc added a comment - It's hard for me to tell whether it's working because I'm accessing Grizzly behind jersey-test. See JERSEY-710 for the related Jersey issue. I can set port to 0, but for this to work I need to be able to find out what concrete port Grizzly ended up using. The unit test web client needs to know which port to connect to. Any idea on how to do that?
        Hide
        oleksiys added a comment -

        fixed in 2.0.1

        For the sample bellow, the output should be:
        port1 = 0
        port2 = N

        where N > 0.

        WBR.

        NetworkListener listener = new NetworkListener("default-port", "0.0.0.0", 0);
        HttpServer httpServer = new HttpServer();
        httpServer.addListener(listener);

        try

        { System.out.println("port1=" + listener.getPort()); httpServer.start(); System.out.println("port2=" + listener.getPort()); System.out.println("Press enter..."); System.in.read(); }

        finally

        { httpServer.stop(); }
        Show
        oleksiys added a comment - fixed in 2.0.1 For the sample bellow, the output should be: port1 = 0 port2 = N where N > 0. WBR. NetworkListener listener = new NetworkListener("default-port", "0.0.0.0", 0); HttpServer httpServer = new HttpServer(); httpServer.addListener(listener); try { System.out.println("port1=" + listener.getPort()); httpServer.start(); System.out.println("port2=" + listener.getPort()); System.out.println("Press enter..."); System.in.read(); } finally { httpServer.stop(); }

          People

          • Assignee:
            Unassigned
            Reporter:
            cowwoc
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: