use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.
the class ZkStateWriterTest method testSingleExternalCollection.
public void testSingleExternalCollection() throws Exception {
String zkDir = createTempDir("testSingleExternalCollection").toFile().getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
SolrZkClient zkClient = null;
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
ZkController.createClusterZkNodes(zkClient);
try (ZkStateReader reader = new ZkStateReader(zkClient)) {
reader.createClusterStateWatchersAndUpdate();
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
// create new collection with stateFormat = 2
ZkWriteCommand c1 = new ZkWriteCommand("c1", new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));
ClusterState clusterState = writer.enqueueUpdate(reader.getClusterState(), c1, null);
writer.writePendingUpdates();
Map map = (Map) Utils.fromJSON(zkClient.getData("/clusterstate.json", null, null, true));
assertNull(map.get("c1"));
map = (Map) Utils.fromJSON(zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true));
assertNotNull(map.get("c1"));
}
} finally {
IOUtils.close(zkClient);
server.shutdown();
}
}
use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.
the class ZkStateWriterTest method testExternalModificationToSharedClusterState.
public void testExternalModificationToSharedClusterState() throws Exception {
String zkDir = createTempDir("testExternalModification").toFile().getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
SolrZkClient zkClient = null;
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
ZkController.createClusterZkNodes(zkClient);
try (ZkStateReader reader = new ZkStateReader(zkClient)) {
reader.createClusterStateWatchersAndUpdate();
ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2", true);
// create collection 1 with stateFormat = 1
ZkWriteCommand c1 = new ZkWriteCommand("c1", new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE));
writer.enqueueUpdate(reader.getClusterState(), c1, null);
writer.writePendingUpdates();
reader.forceUpdateCollection("c1");
reader.forceUpdateCollection("c2");
// keep a reference to the current cluster state object
ClusterState clusterState = reader.getClusterState();
assertTrue(clusterState.hasCollection("c1"));
assertFalse(clusterState.hasCollection("c2"));
// Simulate an external modification to /clusterstate.json
byte[] data = zkClient.getData("/clusterstate.json", null, null, true);
zkClient.setData("/clusterstate.json", data, true);
// enqueue another c1 so that ZkStateWriter has pending updates
writer.enqueueUpdate(clusterState, c1, null);
assertTrue(writer.hasPendingUpdates());
// create collection 2 with stateFormat = 1
ZkWriteCommand c2 = new ZkWriteCommand("c2", new DocCollection("c2", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.getCollectionPath("c2")));
try {
// we are sending in the old cluster state object
writer.enqueueUpdate(clusterState, c2, null);
fail("Enqueue should not have succeeded");
} catch (KeeperException.BadVersionException bve) {
// expected
}
try {
writer.enqueueUpdate(reader.getClusterState(), c2, null);
fail("enqueueUpdate after BadVersionException should not have succeeded");
} catch (IllegalStateException e) {
// expected
}
try {
writer.writePendingUpdates();
fail("writePendingUpdates after BadVersionException should not have succeeded");
} catch (IllegalStateException e) {
// expected
}
}
} finally {
IOUtils.close(zkClient);
server.shutdown();
}
}
use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.
the class ZkSolrClientTest method testWatchChildren.
public void testWatchChildren() throws Exception {
try (ZkConnection conn = new ZkConnection()) {
final SolrZkClient zkClient = conn.getClient();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(1);
zkClient.makePath("/collections", true);
zkClient.getChildren("/collections", new Watcher() {
@Override
public void process(WatchedEvent event) {
cnt.incrementAndGet();
// remake watch
try {
zkClient.getChildren("/collections", this, true);
latch.countDown();
} catch (KeeperException | InterruptedException e) {
throw new RuntimeException(e);
}
}
}, true);
zkClient.makePath("/collections/collection99/shards", true);
//wait until watch has been re-created
latch.await();
zkClient.makePath("collections/collection99/config=collection1", true);
zkClient.makePath("collections/collection99/config=collection3", true);
zkClient.makePath("/collections/collection97/shards", true);
// pause for the watches to fire
Thread.sleep(700);
if (cnt.intValue() < 2) {
// wait a bit more
Thread.sleep(4000);
}
if (cnt.intValue() < 2) {
// wait a bit more
Thread.sleep(4000);
}
assertEquals(2, cnt.intValue());
}
}
use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.
the class ZkSolrClientTest method testClean.
public void testClean() throws Exception {
try (ZkConnection conn = new ZkConnection()) {
final SolrZkClient zkClient = conn.getClient();
zkClient.makePath("/test/path/here", true);
zkClient.makePath("/zz/path/here", true);
zkClient.clean("/");
assertFalse(zkClient.exists("/test", true));
assertFalse(zkClient.exists("/zz", true));
}
}
use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.
the class VMParamsZkACLAndCredentialsProvidersTest method testNoCredentials.
@Test
public void testNoCredentials() throws Exception {
useNoCredentials();
SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
try {
doTest(zkClient, false, false, false, false, false, false, false, false, false, false);
} finally {
zkClient.close();
}
}
Aggregations