Examples of WatchedEvent


Examples of org.apache.zookeeper.WatchedEvent

  public void testWatchDataNode_NoneSyncConnected() throws Exception {
    testWatchDataNode(null, Watcher.Event.EventType.None, true);
  }

  private void testWatchDataNode(byte[] initialData, Watcher.Event.EventType eventType, boolean stillCached) throws Exception {
    WatchedEvent event = new WatchedEvent(eventType, Watcher.Event.KeeperState.SyncConnected, ZPATH);
    TestWatcher exw = new TestWatcher(event);
    zc = new ZooCache(zr, exw);

    Watcher w = watchData(initialData);
    w.process(event);
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

  public void testWatchDataNode_Expired() throws Exception {
    testWatchDataNode_Clear(Watcher.Event.KeeperState.Expired);
  }

  private void testWatchDataNode_Clear(Watcher.Event.KeeperState state) throws Exception {
    WatchedEvent event = new WatchedEvent(Watcher.Event.EventType.None, state, null);
    TestWatcher exw = new TestWatcher(event);
    zc = new ZooCache(zr, exw);

    Watcher w = watchData(DATA);
    assertTrue(zc.dataCached(ZPATH));
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

  public void testWatchChildrenNode_NoneSyncConnected() throws Exception {
    testWatchChildrenNode(CHILDREN, Watcher.Event.EventType.None, true);
  }

  private void testWatchChildrenNode(List<String> initialChildren, Watcher.Event.EventType eventType, boolean stillCached) throws Exception {
    WatchedEvent event = new WatchedEvent(eventType, Watcher.Event.KeeperState.SyncConnected, ZPATH);
    TestWatcher exw = new TestWatcher(event);
    zc = new ZooCache(zr, exw);

    Watcher w = watchChildren(initialChildren);
    w.process(event);
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

    Master master = new Master(protocol, false);
    master.start();
    TestUtil.waitUntilBecomeMaster(master);

    final IDeployClient deployClient = new DeployClient(_protocol);
    WatchedEvent event = new WatchedEvent(new WatcherEvent(EventType.None.getIntValue(), KeeperState.Expired
            .getIntValue(), null));
    for (int i = 0; i < 25; i++) {
      final String indexName = "index" + i;
      IIndexDeployFuture deployFuture = deployClient.addIndex(indexName, INDEX_FILE.getAbsolutePath(), 1);
      zkClient.getEventLock().lock();
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

    ConnectedComponent component1 = mock(ConnectedComponent.class);
    WaitingAnswer waitingAnswer = new WaitingAnswer();
    doAnswer(waitingAnswer).when(component1).disconnect();
    _protocol = _zk.createInteractionProtocol();
    _protocol.registerComponent(component1);
    WatchedEvent expiredEvent = new WatchedEvent(new WatcherEvent(EventType.None.getIntValue(), KeeperState.Expired
            .getIntValue(), null));
    _protocol.getZkClient().process(
            new WatchedEvent(new WatcherEvent(EventType.None.getIntValue(), KeeperState.SyncConnected.getIntValue(),
                    null)));
    _protocol.getZkClient().process(expiredEvent);
    // verify(component1).disconnect();

    ConnectedComponent component2 = mock(ConnectedComponent.class, "2ndComp");
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

            if (children.size() == 0) {
              log.error("There are not gfac instances to route failed jobs");
              return;
            }
            // we recover one gfac node at a time
            final WatchedEvent event = watchedEvent;
            final OrchestratorServerHandler handler = this;
            (new Thread() {
              public void run() {
                int retry = 0;
                while (retry < 3) {
                  try {
                    (new OrchestratorRecoveryHandler(
                        handler, event.getPath()))
                        .recover();
                    break;
                  } catch (Exception e) {
                    e.printStackTrace();
                    log.error("error recovering the jobs for gfac-node: "
                        + event.getPath());
                    log.error("Retrying again to recover jobs and retry attempt: "
                        + ++retry);
                  }
                }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

            public OperationResult<String> getResult() {
                return new OperationResult<String>(data, statistics);
            }
        };

        WatchedEvent event = new WatchedEvent(EventType.NodeCreated, null, "somepath");
        fireEventIn(future, event, 100);
        assertEquals(data, future.get().getResult());
        assertEquals(statistics, future.get().getStatistics());
        assertEquals(event, future.getWatchedEvent());
    }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

        }
        return value;
    }

    public static WatchedEvent getWatchedEvent(ZooKeeperOperation<?> zooKeeperOperation) {
        WatchedEvent watchedEvent = null;
        if (zooKeeperOperation instanceof WatchedEventProvider) {
            watchedEvent = ((WatchedEventProvider)zooKeeperOperation).getWatchedEvent();
        }
        return watchedEvent;
    }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

  /**
   * Simulate a zk state change by calling {@link ZkClient#process(WatchedEvent)} directly
   */
  public static void simulateZkStateDisconnected(ZkClient client) {
    WatchedEvent event = new WatchedEvent(EventType.None, KeeperState.Disconnected, null);
    client.process(event);
  }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

  @Test
  public void testProcessCallbackEventNone() throws Exception {
    mockNoPriorActive();
    elector.joinElection(data);

    WatchedEvent mockEvent = Mockito.mock(WatchedEvent.class);
    Mockito.when(mockEvent.getType()).thenReturn(Event.EventType.None);

    // first SyncConnected should not do anything
    Mockito.when(mockEvent.getState()).thenReturn(
        Event.KeeperState.SyncConnected);
    elector.processWatchEvent(mockZK, mockEvent);
    Mockito.verify(mockZK, Mockito.times(0)).exists(Mockito.anyString(),
        Mockito.anyBoolean(), Mockito.<AsyncCallback.StatCallback> anyObject(),
        Mockito.<Object> anyObject());

    // disconnection should enter safe mode
    Mockito.when(mockEvent.getState()).thenReturn(
        Event.KeeperState.Disconnected);
    elector.processWatchEvent(mockZK, mockEvent);
    Mockito.verify(mockApp, Mockito.times(1)).enterNeutralMode();

    // re-connection should monitor master status
    Mockito.when(mockEvent.getState()).thenReturn(
        Event.KeeperState.SyncConnected);
    elector.processWatchEvent(mockZK, mockEvent);
    verifyExistCall(1);

    // session expired should enter safe mode and initiate re-election
    // re-election checked via checking re-creation of new zookeeper and
    // call to create lock znode
    Mockito.when(mockEvent.getState()).thenReturn(Event.KeeperState.Expired);
    elector.processWatchEvent(mockZK, mockEvent);
    // already in safe mode above. should not enter safe mode again
    Mockito.verify(mockApp, Mockito.times(1)).enterNeutralMode();
    // called getNewZooKeeper to create new session. first call was in
    // constructor
    Assert.assertEquals(2, count);
    // once in initial joinElection and one now
    Mockito.verify(mockZK, Mockito.times(2)).create(ZK_LOCK_NAME, data,
        Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, elector, mockZK);

    // create znode success. become master and monitor
    elector.processResult(Code.OK.intValue(), ZK_LOCK_NAME, mockZK,
        ZK_LOCK_NAME);
    Mockito.verify(mockApp, Mockito.times(1)).becomeActive();
    verifyExistCall(2);

    // error event results in fatal error
    Mockito.when(mockEvent.getState()).thenReturn(Event.KeeperState.AuthFailed);
    elector.processWatchEvent(mockZK, mockEvent);
    Mockito.verify(mockApp, Mockito.times(1)).notifyFatalError(
        "Unexpected Zookeeper watch event state: AuthFailed");
    // only 1 state change callback is called at a time
    Mockito.verify(mockApp, Mockito.times(1)).enterNeutralMode();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.