You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by mm...@apache.org on 2017/11/30 18:11:23 UTC
[accumulo] branch 1.7 updated: ACCUMULO-4546 Create default log
message for table error (#327)
This is an automated email from the ASF dual-hosted git repository.
mmiller pushed a commit to branch 1.7
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/1.7 by this push:
new e738351 ACCUMULO-4546 Create default log message for table error (#327)
e738351 is described below
commit e738351fcdf2359997814c2cf105875702799265
Author: Mark Owens <jm...@gmail.com>
AuthorDate: Thu Nov 30 13:11:21 2017 -0500
ACCUMULO-4546 Create default log message for table error (#327)
---
.../accumulo/server/tables/TableManager.java | 20 ++++++-
.../IllegalTableTransitionExceptionTest.java | 68 ++++++++++++++++++++++
2 files changed, 87 insertions(+), 1 deletion(-)
diff --git a/server/base/src/main/java/org/apache/accumulo/server/tables/TableManager.java b/server/base/src/main/java/org/apache/accumulo/server/tables/TableManager.java
index 0b23061..cb207ec 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/tables/TableManager.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/tables/TableManager.java
@@ -41,6 +41,7 @@ import org.apache.accumulo.server.client.HdfsZooInstance;
import org.apache.accumulo.server.util.TablePropUtil;
import org.apache.accumulo.server.zookeeper.ZooCache;
import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
+import org.apache.commons.lang3.StringUtils;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -115,10 +116,22 @@ public class TableManager {
final TableState oldState;
final TableState newState;
+ final String message;
public IllegalTableTransitionException(TableState oldState, TableState newState) {
+ this(oldState, newState, "");
+ }
+
+ public IllegalTableTransitionException(TableState oldState, TableState newState, String message) {
this.oldState = oldState;
this.newState = newState;
+
+ if (StringUtils.isNotEmpty(message))
+ this.message = message;
+ else {
+ String defaultMessage = "Error transitioning from " + oldState + " state to " + newState + " state";
+ this.message = defaultMessage;
+ }
}
public TableState getOldState() {
@@ -129,6 +142,11 @@ public class TableManager {
return newState;
}
+ @Override
+ public String getMessage() {
+ return message;
+ }
+
}
public synchronized void transitionTableState(final String tableId, final TableState newState) {
@@ -166,7 +184,7 @@ public class TableManager {
}
});
} catch (Exception e) {
- // ACCUMULO-3651 Changed level to error and added FATAL to message for slf4j compability
+ // ACCUMULO-3651 Changed level to error and added FATAL to message for slf4j compatibility
log.error("FATAL Failed to transition table to state " + newState);
throw new RuntimeException(e);
}
diff --git a/server/base/src/test/java/org/apache/accumulo/server/tables/IllegalTableTransitionExceptionTest.java b/server/base/src/test/java/org/apache/accumulo/server/tables/IllegalTableTransitionExceptionTest.java
new file mode 100644
index 0000000..d867ead
--- /dev/null
+++ b/server/base/src/test/java/org/apache/accumulo/server/tables/IllegalTableTransitionExceptionTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.accumulo.server.tables;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.accumulo.core.master.state.tables.TableState;
+import org.apache.accumulo.server.tables.TableManager.IllegalTableTransitionException;
+import org.junit.Test;
+
+public class IllegalTableTransitionExceptionTest {
+
+ final TableState oldState = TableState.ONLINE;
+ final TableState newState = TableState.OFFLINE;
+ final String defaultMsg = "Error transitioning from " + oldState + " state to " + newState + " state";
+
+ @Test
+ public void testIllegalTableTransitionExceptionMessage() {
+ String userMessage = null;
+ try {
+ userMessage = "User suppled message - Exception from " + oldState + " state to " + newState + " state";
+ throw new TableManager.IllegalTableTransitionException(oldState, newState, userMessage);
+ } catch (IllegalTableTransitionException e) {
+ assertEquals(userMessage, e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIllegalTableTransitionExceptionDefaultMessage() {
+ try {
+ throw new TableManager.IllegalTableTransitionException(oldState, newState);
+ } catch (IllegalTableTransitionException e) {
+ assertEquals(defaultMsg, e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIllegalTableTransitionExceptionWithNull() {
+ try {
+ throw new TableManager.IllegalTableTransitionException(oldState, newState, null);
+ } catch (IllegalTableTransitionException e) {
+ assertEquals(defaultMsg, e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIllegalTableTransitionExceptionEmptyMessage() {
+ try {
+ throw new TableManager.IllegalTableTransitionException(oldState, newState, "");
+ } catch (IllegalTableTransitionException e) {
+ assertEquals(defaultMsg, e.getMessage());
+ }
+ }
+}
--
To stop receiving notification emails like this one, please contact
['"commits@accumulo.apache.org" <co...@accumulo.apache.org>'].