Example usage for org.apache.zookeeper WatchedEvent WatchedEvent

List of usage examples for org.apache.zookeeper WatchedEvent WatchedEvent

Introduction

In this page you can find the example usage for org.apache.zookeeper WatchedEvent WatchedEvent.

Prototype

public WatchedEvent(WatcherEvent eventMessage) 

Source Link

Document

Convert a WatcherEvent sent over the wire into a full-fledged WatcherEvent

Usage

From source file:com.dasasian.chok.integration.FailoverTest.java

License:Apache License

@Test(timeout = 100000)
public void testZkMasterReconnectDuringDeployment() throws Exception {
    miniCluster.deployIndex(testIndex, miniCluster.getRunningNodeCount());

    miniCluster.getMaster().shutdown();//  w  w w  .j  av a 2 s . c  o m

    ZkClient zkClient = new ZkClient(miniCluster.getZkConfiguration().getServers());
    InteractionProtocol protocol = new InteractionProtocol(zkClient, miniCluster.getZkConfiguration());
    Master master = new Master(TestMasterConfiguration.getTestConfiguration(), protocol, false);
    master.start();
    TestUtil.waitUntilBecomeMaster(master);

    final IDeployClient deployClient = new DeployClient(miniCluster.getProtocol());
    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, testIndex.getIndexPath(), 1);
        zkClient.getEventLock().lock();
        zkClient.process(event);
        zkClient.getEventLock().unlock();
        IndexState indexState = deployFuture.joinDeployment();
        assertEquals("" + deployClient.getIndexMetaData(indexName).getDeployError(), IndexState.DEPLOYED,
                indexState);

        if (indexState == IndexState.ERROR) {
            IndexDeployError deployError = protocol.getIndexMD(indexName).getDeployError();
            Set<Shard> shards = protocol.getIndexMD(indexName).getShards();
            for (Shard shard : shards) {
                List<Exception> shardErrors = deployError.getShardErrors(shard.getName());
                for (Exception errorDetail : shardErrors) {
                    errorDetail.printStackTrace();
                }
            }
            System.out.println(deployError.getErrorTrace());
        }
    }

    master.shutdown();

    zkClient.close();
}

From source file:com.dasasian.chok.protocol.InteractionProtocolTest.java

License:Apache License

@Test
/**see CHOK-125*/
public void testConcurrentModification() throws Exception {
    ConnectedComponent component1 = Mockito.mock(ConnectedComponent.class);
    WaitingAnswer waitingAnswer = new WaitingAnswer();
    Mockito.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 = Mockito.mock(ConnectedComponent.class, "2ndComp");
    protocol.registerComponent(component2);
    protocol.unregisterComponent(component2);
    waitingAnswer.release();/*from   w ww  .  ja  v  a 2s .  c o m*/
    protocol.disconnect();
}

From source file:com.navercorp.pinpoint.collector.cluster.flink.FlinkClusterService.java

License:Apache License

@PostConstruct
public void setUp() throws KeeperException, IOException, InterruptedException {
    if (!config.isFlinkClusterEnable()) {
        logger.info("flink cluster disable.");
        return;//from  w w  w . j av a  2s.  c o  m
    }

    switch (this.serviceState.getCurrentState()) {
    case NEW:
        if (this.serviceState.changeStateInitializing()) {
            logger.info("{} initialization started.", this.getClass().getSimpleName());

            ClusterManagerWatcher watcher = new ClusterManagerWatcher();
            this.client = new DefaultZookeeperClient(config.getFlinkClusterZookeeperAddress(),
                    config.getFlinkClusterSessionTimeout(), watcher);
            this.client.connect();

            this.zookeeperClusterManager = new ZookeeperClusterManager(client, PINPOINT_FLINK_CLUSTER_PATH,
                    clusterConnectionManager);
            this.zookeeperClusterManager.start();

            this.serviceState.changeStateStarted();
            logger.info("{} initialization completed.", this.getClass().getSimpleName());

            if (client.isConnected()) {
                WatcherEvent watcherEvent = new WatcherEvent(EventType.None.getIntValue(),
                        KeeperState.SyncConnected.getIntValue(), "");
                WatchedEvent event = new WatchedEvent(watcherEvent);
                watcher.process(event);
            }
        }
        break;
    case INITIALIZING:
        logger.info("{} already initializing.", this.getClass().getSimpleName());
        break;
    case STARTED:
        logger.info("{} already started.", this.getClass().getSimpleName());
        break;
    case DESTROYING:
        throw new IllegalStateException("Already destroying.");
    case STOPPED:
        throw new IllegalStateException("Already stopped.");
    case ILLEGAL_STATE:
        throw new IllegalStateException("Invalid State.");
    }
}

From source file:com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperClusterService.java

License:Apache License

@PostConstruct
@Override//from w  w  w  .ja va2s .c o m
public void setUp() throws KeeperException, IOException, InterruptedException {
    if (!config.isClusterEnable()) {
        logger.info("pinpoint-collector cluster disable.");
        return;
    }

    switch (this.serviceState.getCurrentState()) {
    case NEW:
        if (this.serviceState.changeStateInitializing()) {
            logger.info("{} initialization started.", this.getClass().getSimpleName());

            ClusterManagerWatcher watcher = new ClusterManagerWatcher();
            this.client = new DefaultZookeeperClient(config.getClusterAddress(),
                    config.getClusterSessionTimeout(), watcher);
            this.client.connect();

            this.profilerClusterManager = new ZookeeperProfilerClusterManager(client, serverIdentifier,
                    clusterPointRouter.getTargetClusterPointRepository());
            this.profilerClusterManager.start();

            this.webClusterManager = new ZookeeperWebClusterManager(client, PINPOINT_WEB_CLUSTER_PATH,
                    serverIdentifier, clusterConnectionManager);
            this.webClusterManager.start();

            this.serviceState.changeStateStarted();
            logger.info("{} initialization completed.", this.getClass().getSimpleName());

            if (client.isConnected()) {
                WatcherEvent watcherEvent = new WatcherEvent(EventType.None.getIntValue(),
                        KeeperState.SyncConnected.getIntValue(), "");
                WatchedEvent event = new WatchedEvent(watcherEvent);

                watcher.process(event);
            }
        }
        break;
    case INITIALIZING:
        logger.info("{} already initializing.", this.getClass().getSimpleName());
        break;
    case STARTED:
        logger.info("{} already started.", this.getClass().getSimpleName());
        break;
    case DESTROYING:
        throw new IllegalStateException("Already destroying.");
    case STOPPED:
        throw new IllegalStateException("Already stopped.");
    case ILLEGAL_STATE:
        throw new IllegalStateException("Invalid State.");
    }
}

From source file:net.sf.katta.integrationTest.FailoverTest.java

License:Apache License

@Test(timeout = 100000)
public void testZkMasterReconnectDuringDeployment() throws Exception {
    deployTestIndices(1, getNodeCount());
    _miniCluster.getMaster().shutdown();

    ZkClient zkClient = new ZkClient(_miniCluster.getZkConfiguration().getZKServers());
    InteractionProtocol protocol = new InteractionProtocol(zkClient, _miniCluster.getZkConfiguration());
    Master master = new Master(protocol, false);
    master.start();/*from  ww  w .j  av a 2s  .  co  m*/
    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();
        zkClient.process(event);
        zkClient.getEventLock().unlock();
        IndexState indexState = deployFuture.joinDeployment();
        assertEquals("" + deployClient.getIndexMetaData(indexName).getDeployError(), IndexState.DEPLOYED,
                indexState);

        if (indexState == IndexState.ERROR) {
            IndexDeployError deployError = protocol.getIndexMD(indexName).getDeployError();
            Set<Shard> shards = protocol.getIndexMD(indexName).getShards();
            for (Shard shard : shards) {
                List<Exception> shardErrors = deployError.getShardErrors(shard.getName());
                for (Exception exception : shardErrors) {
                    exception.printStackTrace();
                }
            }
            deployError.getException().printStackTrace();
        }
    }
}

From source file:net.sf.katta.protocol.InteractionProtocolTest.java

License:Apache License

@Test
/**see KATTA-125*/
public void testConcurrentModification() throws Exception {
    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");
    _protocol.registerComponent(component2);
    _protocol.unregisterComponent(component2);
    waitingAnswer.release();// www.jav a 2s. c o  m
    _protocol.disconnect();
}