2016-08-06 2 views
1

현재 데이터에 액세스하기 위해 단일 사육사 노드와 큐레이터가있는 설정이 있습니다. 데이터 읽기는 큐레이터 TreeCache를 통해 수행됩니다. 테스트가 실행되기 전에 "new_node는"존재하지 않는사육사가 연속적으로 변경 한 이벤트를 놓쳤습니다.

public void test_callback_successive_changes_success_global_new_version() throws InterruptedException { 

    ZookeeperTestsHelper.createNewNodeInZookeeperSingleCommand("/my/path/new_node", "some string4", curator); 
    ZookeeperTestsHelper.createNewNodeInZookeeperSingleCommand("/my/path/new_node", "some string5", curator); 

    Thread.sleep(1000); 
    assertThat(<check what events the listener heard>); 
} 

참고 :

나는 다음과 같은 시험이있다.

public static void createNewNodeInZookeeperSingleCommand(final String fullPathOfValueInZookeeper, final String valueToSet, final CuratorFramework curator) { 
    try { 
     if (curator.checkExists().forPath(fullPathOfValueInZookeeper) != null) { 
      System.out.println("E: " + valueToSet); 
      //Node already exists just set it 
      curator.setData().forPath(fullPathOfValueInZookeeper, valueToSet.getBytes()); 
     } else { 
      System.out.println("N: " + valueToSet); 
      //Node needs to be created 
      curator.create().creatingParentsIfNeeded().forPath(fullPathOfValueInZookeeper, valueToSet.getBytes()); 
     } 
    } catch (Exception e) { 
     throw new IllegalStateException("Error", e); 
    } 
} 

것은 내가 캐시 리스너가 먼저 "일부 문자열 4"로 추가 된 노드의 이벤트를 듣고 다음 "일부 문자열 5"로 업데이트 노드의 다른 이벤트를 들었을 것이라고 기대하고있다.

대신에 나는 단지 두 명령이 실행되고있는 로그를 보면 "일부 문자열 5"

값이 추가 된 노드에 대한 이벤트를 수신하고 있습니다. 즉 "N : 일부 문자열 4"및 "E : 일부 문자열 5"가 모두 기록됩니다. 그리고 사육사의 최종 값은 정확합니다 ("some string 5").하지만 왜 큐레이터 캐시가 단일 이벤트 만 보는 지 이해할 수 없습니까?

답변

1

ZooKeeper (또는 큐레이터의 TreeCache)는 연속 변경시 이벤트를 놓치지 않는다고 보장하지 않습니다. 다른 클라이언트가 볼 수있는 순서와는 다른 순서로 연속적인 변경 사항을 보지 않을 것이라는 보장이 있습니다.