Uploaded image for project: 'Apache Curator'
  1. Apache Curator
  2. CURATOR-368

powermock will cause curator CONNECTIONLOSS exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Invalid
    • None
    • None
    • Framework
    • None
    • window & linux
      jdk 1.7
      curator-framework 2.9.1
      curator-recipe 2.9.1
      curator-test 2.9.1
      junit 4.12
      powermock-module-junit4 1.6.1
      powermock-api-mockito 1.6.1

    Description

      client code

      public class CuratorClient {
          private CuratorFramework client;
      
          public CuratorClient(String url) {
              this.client = CuratorFrameworkFactory.builder().connectString(url).namespace("test")
                      .retryPolicy(new RetryNTimes(3, 5000))
                      .connectionTimeoutMs(3000).build();
              this.client.start();
          }
      
          public void create(String path) {
              try {
                  this.client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      
          public void lsChildren(String path) {
              try {
                  List<String> children = this.client.getChildren().forPath(path);
                  for (String child : children) {
                      System.out.println(child);
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      
          public void close() {
              this.client.close();
          }
      }
      

      Test code

      @RunWith(PowerMockRunner.class)
      @PrepareForTest({Static.class})
      public class CuratorTest {
          private CuratorClient client;
          private TestingServer server;
      
          @Before
          public void setUp() throws Exception {
              server = new TestingServer();
              server.start();
              client = new CuratorClient(server.getConnectString());
          }
      
          @After
          public void tearDown() throws Exception {
              client.close();
              server.close();
          }
      
          @Test
          public void testCreate() throws Exception {
              client.create("/curator");
          }
      
          @Test
          public void lsChildren() throws Exception {
              client.lsChildren("/curator");
          }
      }
      

      now start testing, you will catch the exception everytime:

      org.apache.curator.CuratorConnectionLossException: KeeperErrorCode = ConnectionLoss
      	at org.apache.curator.ConnectionState.checkTimeouts(ConnectionState.java:195)
      	at org.apache.curator.ConnectionState.getZooKeeper(ConnectionState.java:87)
      	at org.apache.curator.CuratorZookeeperClient.getZooKeeper(CuratorZookeeperClient.java:115)
      	at org.apache.curator.framework.imps.CuratorFrameworkImpl.getZooKeeper(CuratorFrameworkImpl.java:487)
      	at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:720)
      	at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:703)
      	at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107)
      	at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:699)
      	at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:477)
      	at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:467)
      	at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:447)
      	at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:44)
      	at org.alibaba.search.client.CuratorClient.create(CuratorClient.java:25)
      	at org.alibaba.search.client.CuratorTest.testCreate(CuratorTest.java:35)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            xsank xsank mar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: