Github user lvfangmin commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/601#discussion_r214131563
  
    --- Diff: 
src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java ---
    @@ -346,6 +353,211 @@ public void 
testWithMinSessionTimeoutGreaterThanMaxSessionTimeout()
             }
         }
     
    +    /**
    +     * Test verifies that the server shouldn't boot with an invalid 
metrics provider
    +     */
    +    @Test
    +    public void testInvalidMetricsProvider()
    +            throws Exception {
    +        ClientBase.setupTestEnv();
    +
    +        final int CLIENT_PORT = PortAssignment.unique();
    +        final String configs = "metricsProvider.className=BadClass\n";
    +        MainThread main = new MainThread(CLIENT_PORT, true, configs);
    +        String args[] = new String[1];
    +        args[0] = main.confFile.toString();
    +        try {
    +            main.main.initializeAndRun(args);
    +            Assert.fail("Must throw exception as metrics provider is not "
    +                    + "well configured");
    +        } catch (ConfigException iae) {
    +            // expected
    +        }
    +    }
    +
    +    /**
    +     * Test verifies that the server shouldn't boot with a faulty metrics 
provider
    +     */
    +    @Test
    +    public void testFaultyMetricsProviderOnStart()
    +            throws Exception {
    +        ClientBase.setupTestEnv();
    +
    +        final int CLIENT_PORT = PortAssignment.unique();
    +        final String configs = 
"metricsProvider.className="+MetricsProviderWithErrorInStart.class.getName()+"\n";
    +        MainThread main = new MainThread(CLIENT_PORT, true, configs);
    +        String args[] = new String[1];
    +        args[0] = main.confFile.toString();
    +        try {
    +            main.main.initializeAndRun(args);
    +            Assert.fail("Must throw exception as metrics provider is 
cannot boot");
    +        } catch (IOException iae) {
    +            // expected
    +        }
    +    }
    +
    +    /**
    +     * Test verifies that the server shouldn't boot with a faulty metrics 
provider
    +     */
    +    @Test
    +    public void testFaultyMetricsProviderOnConfigure()
    +            throws Exception {
    +        ClientBase.setupTestEnv();
    +
    +        final int CLIENT_PORT = PortAssignment.unique();
    +        final String configs = 
"metricsProvider.className="+MetricsProviderWithErrorInConfigure.class.getName()+"\n";
    +        MainThread main = new MainThread(CLIENT_PORT, true, configs);
    +        String args[] = new String[1];
    +        args[0] = main.confFile.toString();
    +        try {
    +            main.main.initializeAndRun(args);
    +            Assert.fail("Must throw exception as metrics provider is 
cannot boot");
    +        } catch (IOException iae) {
    +            // expected
    +        }
    +    }
    +
    +
    +    /**
    +     * Test verifies that the server shouldn't be affected but runtime 
errors on stop()
    +     */
    +    @Test
    +    public void testFaultyMetricsProviderOnStop()
    +            throws Exception {
    +        ClientBase.setupTestEnv();
    +
    +        final int CLIENT_PORT = PortAssignment.unique();
    +        MetricsProviderWithErrorInStop.stopCalled.set(false);
    +        final String configs = 
"metricsProvider.className="+MetricsProviderWithErrorInStop.class.getName()+"\n";
    +        MainThread main = new MainThread(CLIENT_PORT, true, configs);
    +        main.start();
    +
    +        Assert.assertTrue("waiting for server being up",
    +                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
    +                        CONNECTION_TIMEOUT));
    +
    +        clientConnected = new CountDownLatch(1);
    +        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
    +                ClientBase.CONNECTION_TIMEOUT, this);
    +        Assert.assertTrue("Failed to establish zkclient connection!",
    +                clientConnected.await(CONNECTION_TIMEOUT, 
TimeUnit.MILLISECONDS));
    +
    +        zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
    +                CreateMode.PERSISTENT);
    +        Assert.assertEquals(new String(zk.getData("/foo", null, null)), 
"foobar");
    +        zk.close();
    +
    +        main.shutdown();
    +        main.join();
    +        main.deleteDirs();
    +
    +        Assert.assertTrue("waiting for server down",
    +                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
    +                        ClientBase.CONNECTION_TIMEOUT));
    +        Assert.assertTrue(MetricsProviderWithErrorInStop.stopCalled.get());
    +    }
    +
    +    /**
    +     * Test verifies that configuration is passed to the MetricsProvider.
    +     */
    +    @Test
    +    public void testMetricsProviderConfiguration()
    +            throws Exception {
    +        ClientBase.setupTestEnv();
    +
    +        final int CLIENT_PORT = PortAssignment.unique();
    +        MetricsProviderWithConfiguration.httpPort.set(0);
    +        final String configs = 
"metricsProvider.className="+MetricsProviderWithConfiguration.class.getName()+"\n"+
    +                               "metricsProvider.httpPort=1234\n";
    +        MainThread main = new MainThread(CLIENT_PORT, true, configs);
    +        main.start();
    +
    +        Assert.assertTrue("waiting for server being up",
    --- End diff --
    
    Agreed, we should to it separately in a different patch.


---

Reply via email to