boolean connected = client.blockUntilConnected(3 * connectTimeout, TimeUnit.MILLISECONDS); if (!connected) { if (url.getParameter(Constants.CONFIG_CHECK_KEY, true)) {
private void initCuratorClient(final RegistryCenterConfiguration config) { client.start(); try { if (!client.blockUntilConnected(config.getRetryIntervalMilliseconds() * config.getMaxRetries(), TimeUnit.MILLISECONDS)) { client.close(); throw new OperationTimeoutException(); } } catch (final InterruptedException | OperationTimeoutException ex) { CuratorZookeeperExceptionHandler.handleException(ex); } }
boolean connected = client.blockUntilConnected(3 * connectTimeout, TimeUnit.MILLISECONDS); if (!connected) { if (url.getParameter(Constants.CONFIG_CHECK_KEY, true)) {
public void afterPropertiesSet() throws Exception { this.curatorFramework.blockUntilConnected(); this.initializeSubsystemRollbackDirectory(); this.listenRollbackTransactionAndRegisterWatcher(); }
@Test (expected = IllegalArgumentException.class) public void testServiceAnnouncementFail() throws Exception { curator.start(); curator.blockUntilConnected(); createAndAnnounceServices(ImmutableList.of("placeholder/\u0001")); }
@Before public void setUp() throws Exception { setupServerAndCurator(); curator.start(); curator.blockUntilConnected(); }
@Before public void setUp() throws Exception { setupServerAndCurator(); curator.start(); curator.blockUntilConnected(); }
@Before public void setUp() throws Exception { setupServerAndCurator(); curator.start(); curator.blockUntilConnected(); }
@Override protected void doStart(Listener listener) throws Throwable { client.start(); Logs.RSD.info("init zk client waiting for connected..."); if (!client.blockUntilConnected(1, TimeUnit.MINUTES)) { throw new ZKException("init zk error, config=" + zkConfig); } initLocalCache(zkConfig.getWatchPath()); addConnectionStateListener(); Logs.RSD.info("zk client start success, server lists is:{}", zkConfig.getHosts()); listener.onSuccess(zkConfig.getHosts()); }
public static CuratorFramework createZkClient(TestingServer testingZKServer, Closer closer) throws InterruptedException { CuratorFramework curatorFramework = closer.register(CuratorFrameworkFactory.newClient(testingZKServer.getConnectString(), new RetryOneTime(2000))); curatorFramework.start(); if (! curatorFramework.blockUntilConnected(60, TimeUnit.SECONDS)) { throw new RuntimeException("Time out waiting to connect to ZK!"); } return curatorFramework; } }
void setUp() throws Exception { testingCluster = new TestingCluster(1); testingCluster.start(); cf = CuratorFrameworkFactory.builder() .connectString(testingCluster.getConnectString()) .retryPolicy(new ExponentialBackoffRetry(1, 10)) .compressionProvider(new PotentiallyGzippedCompressionProvider(false)) .build(); cf.start(); cf.blockUntilConnected(); cf.create().creatingParentsIfNeeded().forPath(basePath); cf.create().creatingParentsIfNeeded().forPath(tasksPath); }
@Before public void setUp() throws Exception { setupServerAndCurator(); curator.start(); curator.blockUntilConnected(); curator.create().creatingParentsIfNeeded().forPath(LOAD_QUEUE_PATH); loadQueueCache = new PathChildrenCache( curator, LOAD_QUEUE_PATH, true, true, Execs.singleThreaded("load_queue_cache-%d") ); }
@Test(timeout = 60_000L) public void testCreateIfNotExistsPayloadTooLarge() throws Exception { curator.start(); curator.blockUntilConnected(); Exception thrown = null; try { CuratorUtils.createIfNotExists( curator, "/foo/bar", CreateMode.PERSISTENT, StringUtils.toUtf8("baz"), 2 ); } catch (Exception e) { thrown = e; } Assert.assertTrue(thrown instanceof IllegalArgumentException); Assert.assertNull(curator.checkExists().forPath("/foo/bar")); }
@Test(timeout = 60_000L) public void testCreateOrSetPayloadTooLarge() throws Exception { curator.start(); curator.blockUntilConnected(); Exception thrown = null; try { CuratorUtils.createOrSet( curator, "/foo/bar", CreateMode.PERSISTENT, StringUtils.toUtf8("baz"), 2 ); } catch (Exception e) { thrown = e; } Assert.assertTrue(thrown instanceof IllegalArgumentException); Assert.assertNull(curator.checkExists().forPath("/foo/bar")); } }
public void afterPropertiesSet() throws Exception { if (this.initializeEnabled) { this.initializeIndexIfNecessary(); } this.curatorFramework.blockUntilConnected(); this.curatorFramework.getConnectionStateListenable().addListener(this); this.initializeClusterInstancesDirectory(); this.initializeClusterInstanceVersion(); this.initializeClusterInstanceConfig(true); }
@Test(timeout = 60_000L) public void testCreateOrSet() throws Exception { curator.start(); curator.blockUntilConnected(); Assert.assertNull(curator.checkExists().forPath("/foo/bar")); CuratorUtils.createOrSet( curator, "/foo/bar", CreateMode.PERSISTENT, StringUtils.toUtf8("baz"), 3 ); Assert.assertEquals("baz", StringUtils.fromUtf8(curator.getData().forPath("/foo/bar"))); CuratorUtils.createOrSet( curator, "/foo/bar", CreateMode.PERSISTENT, StringUtils.toUtf8("qux"), 3 ); Assert.assertEquals("qux", StringUtils.fromUtf8(curator.getData().forPath("/foo/bar"))); }
@Test public void testLeavesBehindTurdlingsWhenToldTo() throws Exception { curator.start(); curator.blockUntilConnected(); Announcer announcer = new Announcer(curator, exec); final byte[] billy = StringUtils.toUtf8("billy"); final String testPath = "/somewhere/test2"; final String parent = ZKPaths.getPathAndNode(testPath).getPath(); announcer.start(); try { Assert.assertNull(curator.checkExists().forPath(parent)); awaitAnnounce(announcer, testPath, billy, false); Assert.assertNotNull(curator.checkExists().forPath(parent)); } finally { announcer.stop(); } Assert.assertNotNull(curator.checkExists().forPath(parent)); }
@Test public void testCleansUpItsLittleTurdlings() throws Exception { curator.start(); curator.blockUntilConnected(); Announcer announcer = new Announcer(curator, exec); final byte[] billy = StringUtils.toUtf8("billy"); final String testPath = "/somewhere/test2"; final String parent = ZKPaths.getPathAndNode(testPath).getPath(); announcer.start(); try { Assert.assertNull(curator.checkExists().forPath(parent)); awaitAnnounce(announcer, testPath, billy, true); Assert.assertNotNull(curator.checkExists().forPath(parent)); } finally { announcer.stop(); } Assert.assertNull(curator.checkExists().forPath(parent)); }
@Test(timeout = 60_000L) public void testCreateIfNotExists() throws Exception { curator.start(); curator.blockUntilConnected(); CuratorUtils.createIfNotExists( curator, "/foo/bar", CreateMode.PERSISTENT, StringUtils.toUtf8("baz"), CuratorUtils.DEFAULT_MAX_ZNODE_BYTES ); Assert.assertEquals("baz", StringUtils.fromUtf8(curator.getData().forPath("/foo/bar"))); CuratorUtils.createIfNotExists( curator, "/foo/bar", CreateMode.PERSISTENT, StringUtils.toUtf8("qux"), CuratorUtils.DEFAULT_MAX_ZNODE_BYTES ); Assert.assertEquals("baz", StringUtils.fromUtf8(curator.getData().forPath("/foo/bar"))); }
@Test public void testLeavesBehindTurdlingsThatAlreadyExisted() throws Exception { curator.start(); curator.blockUntilConnected(); Announcer announcer = new Announcer(curator, exec); final byte[] billy = StringUtils.toUtf8("billy"); final String testPath = "/somewhere/test2"; final String parent = ZKPaths.getPathAndNode(testPath).getPath(); curator.create().forPath(parent); final Stat initialStat = curator.checkExists().forPath(parent); announcer.start(); try { Assert.assertEquals(initialStat.getMzxid(), curator.checkExists().forPath(parent).getMzxid()); awaitAnnounce(announcer, testPath, billy, true); Assert.assertEquals(initialStat.getMzxid(), curator.checkExists().forPath(parent).getMzxid()); } finally { announcer.stop(); } Assert.assertEquals(initialStat.getMzxid(), curator.checkExists().forPath(parent).getMzxid()); }