This is an automated email from the ASF dual-hosted git repository.
kennethmcfarland pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/fluo.git
The following commit(s) were added to refs/heads/master by this push:
new 1cc9276 FLUO-1002 Create integration test for `FluoAdmin.remove()`
(#1043)
1cc9276 is described below
commit 1cc9276e454505b82d15f72ef7be1c3008606d43
Author: Kenneth Paul McFarland <[email protected]>
AuthorDate: Mon Jul 9 08:57:34 2018 -0700
FLUO-1002 Create integration test for `FluoAdmin.remove()` (#1043)
FLUO-1002 Integration test for FluoAdmin.remove()
---
.../org/apache/fluo/core/client/FluoAdminImpl.java | 5 ++
.../apache/fluo/core/util/OracleServerUtils.java | 46 +++++++++++++
.../fluo/integration/client/FluoAdminImplIT.java | 80 ++++++++++++++++++++++
3 files changed, 131 insertions(+)
diff --git
a/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
b/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
index 1da5155..8bea85f 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
@@ -55,6 +55,7 @@ import org.apache.fluo.core.impl.FluoConfigurationImpl;
import org.apache.fluo.core.observer.ObserverUtil;
import org.apache.fluo.core.util.AccumuloUtil;
import org.apache.fluo.core.util.CuratorUtil;
+import org.apache.fluo.core.util.OracleServerUtils;
import org.apache.fluo.core.worker.finder.hash.PartitionManager;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
@@ -211,6 +212,10 @@ public class FluoAdminImpl implements FluoAdmin {
"The Zookeeper connection string (set by 'fluo.connection.zookeepers')
"
+ " must have a chroot suffix.");
+ if (OracleServerUtils.oracleExists(getAppCurator())) {
+ throw new FluoException("Must stop the oracle server to remove an
application");
+ }
+
Connector conn = AccumuloUtil.getConnector(config);
boolean tableExists =
conn.tableOperations().exists(config.getAccumuloTable());
diff --git
a/modules/core/src/main/java/org/apache/fluo/core/util/OracleServerUtils.java
b/modules/core/src/main/java/org/apache/fluo/core/util/OracleServerUtils.java
new file mode 100644
index 0000000..cb6f5fe
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/fluo/core/util/OracleServerUtils.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+
+package org.apache.fluo.core.util;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.fluo.accumulo.util.ZookeeperPath;
+import org.apache.zookeeper.KeeperException;
+
+public class OracleServerUtils {
+
+ private OracleServerUtils() {}
+
+ /**
+ * Checks to see if an Oracle Server exists.
+ *
+ * @param curator It is the responsibility of the caller to ensure the
curator is started
+ * @return boolean if the server exists in zookeeper
+ */
+ public static boolean oracleExists(CuratorFramework curator) {
+ boolean exists = false;
+ try {
+ exists = curator.checkExists().forPath(ZookeeperPath.ORACLE_SERVER) !=
null
+ &&
!curator.getChildren().forPath(ZookeeperPath.ORACLE_SERVER).isEmpty();
+ } catch (Exception nne) {
+ if (nne instanceof KeeperException.NoNodeException) {
+ // you'll do nothing
+ } else {
+ throw new RuntimeException(nne);
+ }
+ }
+ return exists;
+ }
+}
diff --git
a/modules/integration/src/test/java/org/apache/fluo/integration/client/FluoAdminImplIT.java
b/modules/integration/src/test/java/org/apache/fluo/integration/client/FluoAdminImplIT.java
index 02b8edc..f3052dd 100644
---
a/modules/integration/src/test/java/org/apache/fluo/integration/client/FluoAdminImplIT.java
+++
b/modules/integration/src/test/java/org/apache/fluo/integration/client/FluoAdminImplIT.java
@@ -19,6 +19,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import com.google.common.collect.Iterables;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.ZooKeeperInstance;
@@ -30,9 +31,17 @@ import org.apache.fluo.api.client.FluoAdmin;
import org.apache.fluo.api.client.FluoAdmin.AlreadyInitializedException;
import org.apache.fluo.api.client.FluoAdmin.InitializationOptions;
import org.apache.fluo.api.client.FluoAdmin.TableExistsException;
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.client.FluoFactory;
+import org.apache.fluo.api.client.Snapshot;
+import org.apache.fluo.api.client.Transaction;
import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.exceptions.FluoException;
import org.apache.fluo.core.client.FluoAdminImpl;
import org.apache.fluo.core.client.FluoClientImpl;
+import org.apache.fluo.core.impl.Environment;
+import org.apache.fluo.core.oracle.OracleServer;
import org.apache.fluo.core.util.CuratorUtil;
import org.apache.fluo.integration.ITBaseImpl;
import org.apache.hadoop.io.Text;
@@ -184,4 +193,75 @@ public class FluoAdminImplIT extends ITBaseImpl {
}
}
+ @Test
+ public void testRemove() throws Exception {
+
+ try (FluoAdmin admin = new FluoAdminImpl(config)) {
+ admin.remove();
+ fail("This should fail with the oracle server running");
+ } catch (FluoException e) {
+ }
+
+ // write/verify some data
+ String row = "Logicians";
+ Column fname = new Column("name", "first");
+ Column lname = new Column("name", "last");
+
+ try (FluoClient client = FluoFactory.newClient(config)) {
+ try (Transaction tx = client.newTransaction()) {
+ tx.set(row, fname, "Kurt");
+ tx.set(row, lname, "Godel");
+ tx.commit();
+ }
+ // read it for sanity
+ try (Snapshot snap = client.newSnapshot()) {
+ Assert.assertEquals("Kurt", snap.gets(row, fname));
+ Assert.assertEquals("Godel", snap.gets(row, lname));
+ Assert.assertEquals(2, Iterables.size(snap.scanner().build()));
+ }
+ }
+
+ oserver.stop();
+
+ try (FluoAdmin admin = new FluoAdminImpl(config)) {
+ admin.remove(); // pass with oracle stopped
+ }
+
+ try (FluoAdmin admin = new FluoAdminImpl(config)) {
+ InitializationOptions opts =
+ new
InitializationOptions().setClearTable(false).setClearZookeeper(false);
+ admin.initialize(opts);
+ }
+
+ // necessary workaround due to cached application id
+ Environment env2 = new Environment(config);
+ OracleServer oserver2 = new OracleServer(env2);
+ oserver2.start();
+
+ // verify empty
+ try (FluoClient client = FluoFactory.newClient(config)) {
+ try (Snapshot snap = client.newSnapshot()) {
+ Assert.assertEquals(0, Iterables.size(snap.scanner().build()));
+ }
+ }
+
+ try (FluoClient client = FluoFactory.newClient(config)) {
+ // write data
+ try (Transaction tx = client.newTransaction()) {
+ tx.set(row, fname, "Stephen");
+ tx.set(row, lname, "Kleene");
+ tx.commit();
+ }
+ // read data
+ try (Snapshot snap = client.newSnapshot()) {
+ Assert.assertEquals("Stephen", snap.gets(row, fname));
+ Assert.assertEquals("Kleene", snap.gets(row, lname));
+ Assert.assertEquals(2, Iterables.size(snap.scanner().build()));
+ }
+ }
+
+ oserver2.stop();
+ env2.close();
+
+ }
}