You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ka...@apache.org on 2018/06/21 05:51:03 UTC
[12/31] metamodel git commit: HBase unittests improvements (fixed
issues when the testfile wasn't setup)
HBase unittests improvements (fixed issues when the testfile wasn't setup)
Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/54a900b4
Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/54a900b4
Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/54a900b4
Branch: refs/heads/master
Commit: 54a900b4c9a608687239982d602c8eabc67f3afa
Parents: 9ab3004
Author: Gerard Dellemann <g....@quadient.com>
Authored: Wed May 30 10:54:22 2018 +0200
Committer: Gerard Dellemann <g....@quadient.com>
Committed: Wed May 30 10:54:22 2018 +0200
----------------------------------------------------------------------
.../apache/metamodel/hbase/CreateTableTest.java | 122 ++++++++++++-------
.../apache/metamodel/hbase/DeleteRowTest.java | 54 +++++---
.../apache/metamodel/hbase/DropTableTest.java | 22 +++-
.../apache/metamodel/hbase/HBaseTestCase.java | 40 +++---
.../hbase/HBaseUpdateCallbackTest.java | 22 ++--
.../apache/metamodel/hbase/InsertRowTest.java | 9 +-
6 files changed, 169 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metamodel/blob/54a900b4/hbase/src/test/java/org/apache/metamodel/hbase/CreateTableTest.java
----------------------------------------------------------------------
diff --git a/hbase/src/test/java/org/apache/metamodel/hbase/CreateTableTest.java b/hbase/src/test/java/org/apache/metamodel/hbase/CreateTableTest.java
index e804a67..5655e4a 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/CreateTableTest.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/CreateTableTest.java
@@ -31,19 +31,29 @@ public class CreateTableTest extends HBaseUpdateCallbackTest {
* Check if creating table is supported
*/
public void testDropTableSupported() {
- assertTrue(getUpdateCallback().isCreateTableSupported());
+ if (isConfigured()) {
+ assertTrue(getUpdateCallback().isCreateTableSupported());
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
+ }
}
/**
* Create a table with an immutableSchema, should throw a IllegalArgumentException
*/
public void testWrongSchema() {
- final ImmutableSchema immutableSchema = new ImmutableSchema(getSchema());
- try {
- getUpdateCallback().createTable(immutableSchema, TABLE_NAME).execute();
- fail("Should get an exception that the schema isn't mutable");
- } catch (IllegalArgumentException e) {
- assertEquals("Not a mutable schema: " + immutableSchema, e.getMessage());
+ if (isConfigured()) {
+ final ImmutableSchema immutableSchema = new ImmutableSchema(getSchema());
+ try {
+ getUpdateCallback().createTable(immutableSchema, TABLE_NAME).execute();
+ fail("Should get an exception that the schema isn't mutable");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Not a mutable schema: " + immutableSchema, e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
@@ -51,11 +61,16 @@ public class CreateTableTest extends HBaseUpdateCallbackTest {
* Create a table without columnFamilies, should throw a MetaModelException
*/
public void testCreateTableWithoutColumnFamilies() {
- try {
- getUpdateCallback().createTable(getSchema(), TABLE_NAME).execute();
- fail("Should get an exception that the columnFamilies haven't been set");
- } catch (MetaModelException e) {
- assertEquals("Creating a table without columnFamilies", e.getMessage());
+ if (isConfigured()) {
+ try {
+ getUpdateCallback().createTable(getSchema(), TABLE_NAME).execute();
+ fail("Should get an exception that the columnFamilies haven't been set");
+ } catch (MetaModelException e) {
+ assertEquals("Creating a table without columnFamilies", e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
@@ -63,11 +78,16 @@ public class CreateTableTest extends HBaseUpdateCallbackTest {
* Create a table with columnFamilies null, should throw a MetaModelException
*/
public void testColumnFamiliesNull() {
- try {
- getUpdateCallback().createTable(getSchema(), TABLE_NAME, null).execute();
- fail("Should get an exception that the columnFamilies haven't been set");
- } catch (MetaModelException e) {
- assertEquals("Creating a table without columnFamilies", e.getMessage());
+ if (isConfigured()) {
+ try {
+ getUpdateCallback().createTable(getSchema(), TABLE_NAME, null).execute();
+ fail("Should get an exception that the columnFamilies haven't been set");
+ } catch (MetaModelException e) {
+ assertEquals("Creating a table without columnFamilies", e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
@@ -75,12 +95,17 @@ public class CreateTableTest extends HBaseUpdateCallbackTest {
* Create a table with columnFamilies empty, should throw a MetaModelException
*/
public void testColumnFamiliesEmpty() {
- try {
- final LinkedHashSet<String> columnFamilies = new LinkedHashSet<String>();
- getUpdateCallback().createTable(getSchema(), TABLE_NAME, columnFamilies).execute();
- fail("Should get an exception that the columnFamilies haven't been set");
- } catch (MetaModelException e) {
- assertEquals("Creating a table without columnFamilies", e.getMessage());
+ if (isConfigured()) {
+ try {
+ final LinkedHashSet<String> columnFamilies = new LinkedHashSet<String>();
+ getUpdateCallback().createTable(getSchema(), TABLE_NAME, columnFamilies).execute();
+ fail("Should get an exception that the columnFamilies haven't been set");
+ } catch (MetaModelException e) {
+ assertEquals("Creating a table without columnFamilies", e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
@@ -112,13 +137,18 @@ public class CreateTableTest extends HBaseUpdateCallbackTest {
* Creating a HBaseClient with the tableName null, should throw a exception
*/
public void testCreatingTheHBaseClientWithTableNameNull() {
- try {
- final LinkedHashSet<String> columnFamilies = new LinkedHashSet<>();
- columnFamilies.add("1");
- new HBaseClient(getDataContext().getConnection()).createTable(null, columnFamilies);
- fail("Should get an exception that tableName is null");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't create a table without having the tableName or columnFamilies", e.getMessage());
+ if (isConfigured()) {
+ try {
+ final LinkedHashSet<String> columnFamilies = new LinkedHashSet<>();
+ columnFamilies.add("1");
+ new HBaseClient(getDataContext().getConnection()).createTable(null, columnFamilies);
+ fail("Should get an exception that tableName is null");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Can't create a table without having the tableName or columnFamilies", e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
@@ -126,11 +156,16 @@ public class CreateTableTest extends HBaseUpdateCallbackTest {
* Creating a HBaseClient with the tableName null, should throw a exception
*/
public void testCreatingTheHBaseClientWithColumnFamiliesNull() {
- try {
- new HBaseClient(getDataContext().getConnection()).createTable("1", null);
- fail("Should get an exception that columnFamilies is null");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't create a table without having the tableName or columnFamilies", e.getMessage());
+ if (isConfigured()) {
+ try {
+ new HBaseClient(getDataContext().getConnection()).createTable("1", null);
+ fail("Should get an exception that columnFamilies is null");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Can't create a table without having the tableName or columnFamilies", e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
@@ -138,12 +173,17 @@ public class CreateTableTest extends HBaseUpdateCallbackTest {
* Creating a HBaseClient with the tableName null, should throw a exception
*/
public void testCreatingTheHBaseClientWithColumnFamiliesEmpty() {
- try {
- final LinkedHashSet<String> columnFamilies = new LinkedHashSet<>();
- new HBaseClient(getDataContext().getConnection()).createTable("1", columnFamilies);
- fail("Should get an exception that columnFamilies is empty");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't create a table without having the tableName or columnFamilies", e.getMessage());
+ if (isConfigured()) {
+ try {
+ final LinkedHashSet<String> columnFamilies = new LinkedHashSet<>();
+ new HBaseClient(getDataContext().getConnection()).createTable("1", columnFamilies);
+ fail("Should get an exception that columnFamilies is empty");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Can't create a table without having the tableName or columnFamilies", e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/54a900b4/hbase/src/test/java/org/apache/metamodel/hbase/DeleteRowTest.java
----------------------------------------------------------------------
diff --git a/hbase/src/test/java/org/apache/metamodel/hbase/DeleteRowTest.java b/hbase/src/test/java/org/apache/metamodel/hbase/DeleteRowTest.java
index 8d21194..893b956 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/DeleteRowTest.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/DeleteRowTest.java
@@ -31,19 +31,29 @@ public class DeleteRowTest extends HBaseUpdateCallbackTest {
* Delete is supported
*/
public void testDeleteSupported() {
- assertTrue(getUpdateCallback().isDeleteSupported());
+ if (isConfigured()) {
+ assertTrue(getUpdateCallback().isDeleteSupported());
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
+ }
}
/**
* Having the table type wrong, should throw an exception
*/
public void testTableWrongType() {
- final MutableTable mutableTable = new MutableTable();
- try {
- getUpdateCallback().deleteFrom(mutableTable);
- fail("Should get an exception that the type of the table is wrong.");
- } catch (IllegalArgumentException e) {
- assertEquals("Not an HBase table: " + mutableTable, e.getMessage());
+ if (isConfigured()) {
+ final MutableTable mutableTable = new MutableTable();
+ try {
+ getUpdateCallback().deleteFrom(mutableTable);
+ fail("Should get an exception that the type of the table is wrong.");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Not an HBase table: " + mutableTable, e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
@@ -91,11 +101,16 @@ public class DeleteRowTest extends HBaseUpdateCallbackTest {
* Creating a HBaseClient with the tableName null, should throw a exception
*/
public void testCreatingTheHBaseClientWithTableNameNull() {
- try {
- new HBaseClient(getDataContext().getConnection()).deleteRow(null, new String("1"));
- fail("Should get an exception that tableName is null");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't delete a row without having tableName or rowKey", e.getMessage());
+ if (isConfigured()) {
+ try {
+ new HBaseClient(getDataContext().getConnection()).deleteRow(null, new String("1"));
+ fail("Should get an exception that tableName is null");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Can't delete a row without having tableName or rowKey", e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
@@ -103,11 +118,16 @@ public class DeleteRowTest extends HBaseUpdateCallbackTest {
* Creating a HBaseClient with the rowKey null, should throw a exception
*/
public void testCreatingTheHBaseClientWithRowKeyNull() {
- try {
- new HBaseClient(getDataContext().getConnection()).deleteRow("tableName", null);
- fail("Should get an exception that rowKey is null");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't delete a row without having tableName or rowKey", e.getMessage());
+ if (isConfigured()) {
+ try {
+ new HBaseClient(getDataContext().getConnection()).deleteRow("tableName", null);
+ fail("Should get an exception that rowKey is null");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Can't delete a row without having tableName or rowKey", e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/54a900b4/hbase/src/test/java/org/apache/metamodel/hbase/DropTableTest.java
----------------------------------------------------------------------
diff --git a/hbase/src/test/java/org/apache/metamodel/hbase/DropTableTest.java b/hbase/src/test/java/org/apache/metamodel/hbase/DropTableTest.java
index d5b19ef..39bb06d 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/DropTableTest.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/DropTableTest.java
@@ -30,7 +30,12 @@ public class DropTableTest extends HBaseUpdateCallbackTest {
* Check if drop table is supported
*/
public void testDropTableSupported() {
- assertTrue(getUpdateCallback().isDropTableSupported());
+ if (isConfigured()) {
+ assertTrue(getUpdateCallback().isDropTableSupported());
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
+ }
}
/**
@@ -55,11 +60,16 @@ public class DropTableTest extends HBaseUpdateCallbackTest {
* Creating a HBaseClient with the tableName null, should throw a exception
*/
public void testCreatingTheHBaseClientWithTableNameNull() {
- try {
- new HBaseClient(getDataContext().getConnection()).dropTable(null);
- fail("Should get an exception that tableName is null");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't drop a table without having the tableName", e.getMessage());
+ if (isConfigured()) {
+ try {
+ new HBaseClient(getDataContext().getConnection()).dropTable(null);
+ fail("Should get an exception that tableName is null");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Can't drop a table without having the tableName", e.getMessage());
+ }
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
}
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/54a900b4/hbase/src/test/java/org/apache/metamodel/hbase/HBaseTestCase.java
----------------------------------------------------------------------
diff --git a/hbase/src/test/java/org/apache/metamodel/hbase/HBaseTestCase.java b/hbase/src/test/java/org/apache/metamodel/hbase/HBaseTestCase.java
index 91180cb..70fd2e3 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/HBaseTestCase.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/HBaseTestCase.java
@@ -63,40 +63,34 @@ public abstract class HBaseTestCase extends TestCase {
private boolean _configured;
private static HBaseDataContext _dataContext;
- private boolean setUpIsDone = false;
-
@Override
protected void setUp() throws Exception {
super.setUp();
- if (!setUpIsDone) {
- Properties properties = new Properties();
- File file = new File(getPropertyFilePath());
- if (file.exists()) {
- properties.load(new FileReader(file));
- zookeeperHostname = properties.getProperty("hbase.zookeeper.hostname");
- String zookeeperPortPropertyValue = properties.getProperty("hbase.zookeeper.port");
- if (zookeeperPortPropertyValue != null && !zookeeperPortPropertyValue.isEmpty()) {
- zookeeperPort = Integer.parseInt(zookeeperPortPropertyValue);
- }
-
- _configured = (zookeeperHostname != null && !zookeeperHostname.isEmpty());
- } else {
- _configured = false;
- }
- if (isConfigured()) {
- final HBaseConfiguration configuration = new HBaseConfiguration(zookeeperHostname, zookeeperPort,
- ColumnType.VARCHAR);
- setDataContext(new HBaseDataContext(configuration));
+ Properties properties = new Properties();
+ File file = new File(getPropertyFilePath());
+ if (file.exists()) {
+ properties.load(new FileReader(file));
+ zookeeperHostname = properties.getProperty("hbase.zookeeper.hostname");
+ String zookeeperPortPropertyValue = properties.getProperty("hbase.zookeeper.port");
+ if (zookeeperPortPropertyValue != null && !zookeeperPortPropertyValue.isEmpty()) {
+ zookeeperPort = Integer.parseInt(zookeeperPortPropertyValue);
}
- setUpIsDone = true;
+
+ _configured = (zookeeperHostname != null && !zookeeperHostname.isEmpty());
+ } else {
+ _configured = false;
+ }
+ if (isConfigured()) {
+ final HBaseConfiguration configuration = new HBaseConfiguration(zookeeperHostname, zookeeperPort,
+ ColumnType.VARCHAR);
+ setDataContext(new HBaseDataContext(configuration));
}
}
@AfterClass
public static void oneTimeTeardown() throws IOException {
_dataContext.getConnection().close();
- ;
}
private String getPropertyFilePath() {
http://git-wip-us.apache.org/repos/asf/metamodel/blob/54a900b4/hbase/src/test/java/org/apache/metamodel/hbase/HBaseUpdateCallbackTest.java
----------------------------------------------------------------------
diff --git a/hbase/src/test/java/org/apache/metamodel/hbase/HBaseUpdateCallbackTest.java b/hbase/src/test/java/org/apache/metamodel/hbase/HBaseUpdateCallbackTest.java
index b010c71..60a5ba6 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/HBaseUpdateCallbackTest.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/HBaseUpdateCallbackTest.java
@@ -43,19 +43,19 @@ public abstract class HBaseUpdateCallbackTest extends HBaseTestCase {
private HBaseUpdateCallback updateCallback;
private MutableSchema schema;
- private boolean setUpIsDone = false;
+ private static boolean warningGiven = false;
@Override
protected void setUp() throws Exception {
super.setUp();
if (isConfigured()) {
- if (setUpIsDone) {
- dropTableIfItExists();
- } else {
- updateCallback = new HBaseUpdateCallback(getDataContext());
- schema = (MutableSchema) getDataContext().getDefaultSchema();
- dropTableIfItExists();
- setUpIsDone = true;
+ updateCallback = new HBaseUpdateCallback(getDataContext());
+ schema = (MutableSchema) getDataContext().getDefaultSchema();
+ dropTableIfItExists();
+ } else {
+ if (!warningGiven) {
+ System.err.println(getInvalidConfigurationMessage());
+ warningGiven = true;
}
}
}
@@ -187,9 +187,9 @@ public abstract class HBaseUpdateCallbackTest extends HBaseTestCase {
}
protected void warnAboutANotExecutedTest(String className, String methodName) {
- String logWarning = "Test(method) \"" + className + "#" + methodName
- + "\" is not executed, because the HBasetest is not configured.";
- // System.out.println(logWarning);
+ String logWarning = "Test \"" + className + "#" + methodName
+ + "()\" is not executed, because the HBasetest is not configured.";
+ System.err.println(logWarning);
logger.warn(logWarning);
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/54a900b4/hbase/src/test/java/org/apache/metamodel/hbase/InsertRowTest.java
----------------------------------------------------------------------
diff --git a/hbase/src/test/java/org/apache/metamodel/hbase/InsertRowTest.java b/hbase/src/test/java/org/apache/metamodel/hbase/InsertRowTest.java
index 622b70b..7a1705f 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/InsertRowTest.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/InsertRowTest.java
@@ -34,7 +34,12 @@ public class InsertRowTest extends HBaseUpdateCallbackTest {
* @throws IOException
*/
public void testInsertSupported() throws IOException {
- assertTrue(getUpdateCallback().isInsertSupported());
+ if (isConfigured()) {
+ assertTrue(getUpdateCallback().isInsertSupported());
+ } else {
+ warnAboutANotExecutedTest(getClass().getName(), new Object() {
+ }.getClass().getEnclosingMethod().getName());
+ }
}
/**
@@ -63,7 +68,7 @@ public class InsertRowTest extends HBaseUpdateCallbackTest {
*/
public void testWrongTableType() throws IOException {
if (isConfigured()) {
- MutableTable mutableTable = new MutableTable();
+ final MutableTable mutableTable = new MutableTable();
try {
final HBaseTable existingTable = createAndInsertTable(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
CF_BAR);