kpm1985 closed pull request #1043: FLUO-1002 Create integration test for 
`FluoAdmin.remove()`
URL: https://github.com/apache/fluo/pull/1043
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 1da5155a..8bea85f5 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.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 void remove() {
         "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 00000000..cb6f5fe8
--- /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 02b8edc6..f3052dd5 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.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.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 void testInitializeLongChroot() throws Exception {
     }
   }
 
+  @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();
+
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to