HBaseClient.java:
- Remove overabundant `;` on line 111 ("try (final Table table =
_connection.getTable(TableName.valueOf(tableName));) {").
- Remove overabundant " == true" on line 112 ("if (rowExists(table,
rowKeyAsByteArray) == true) {").
- On line 115 use a Marker object when inserting variables into log messages.
- Add final modifier on line 144 ("public void createTable(String tableName,
Set<String> columnFamilies) {").
HBaseCreateTableBuilder.java:
- On line 81 make the parameters of the setColumnFamilies method final.
HBaseRow.java:
- Revert remmoval of empty line (62).
HBaseRowDeletionBuilder.java:
- The _dataContext field member has to be made final
- On line 58 make the key par
Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/5313a492
Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/5313a492
Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/5313a492
Branch: refs/heads/master
Commit: 5313a492f7c733be367c2738af14bc566a6090e1
Parents: 4a928d1
Author: Arjan Seijkens <[email protected]>
Authored: Wed Jun 6 10:12:02 2018 +0200
Committer: Arjan Seijkens <[email protected]>
Committed: Wed Jun 6 10:12:02 2018 +0200
----------------------------------------------------------------------
.../org/apache/metamodel/hbase/HBaseClient.java | 8 +-
.../hbase/HBaseCreateTableBuilder.java | 12 +-
.../org/apache/metamodel/hbase/HBaseRow.java | 1 +
.../hbase/HBaseRowDeletionBuilder.java | 6 +-
.../apache/metamodel/hbase/CreateTableTest.java | 159 +++-----
.../apache/metamodel/hbase/DeleteRowTest.java | 155 ++++----
.../apache/metamodel/hbase/DropTableTest.java | 47 ++-
.../apache/metamodel/hbase/HBaseTestCase.java | 3 +-
.../hbase/HBaseUpdateCallbackTest.java | 88 ++---
.../apache/metamodel/hbase/InsertRowTest.java | 363 +++++++++----------
10 files changed, 365 insertions(+), 477 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/hbase/src/main/java/org/apache/metamodel/hbase/HBaseClient.java
----------------------------------------------------------------------
diff --git a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseClient.java
b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseClient.java
index a9040fc..a868a93 100644
--- a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseClient.java
+++ b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseClient.java
@@ -108,11 +108,11 @@ final class HBaseClient {
}
byte[] rowKeyAsByteArray = getValueAsByteArray(rowKey);
if (rowKeyAsByteArray.length > 0) {
- try (final Table table =
_connection.getTable(TableName.valueOf(tableName));) {
- if (rowExists(table, rowKeyAsByteArray) == true) {
+ try (final Table table =
_connection.getTable(TableName.valueOf(tableName))) {
+ if (rowExists(table, rowKeyAsByteArray)) {
table.delete(new Delete(rowKeyAsByteArray));
} else {
- logger.warn("Rowkey with value " + rowKey.toString() + "
doesn't exist in the table");
+ logger.warn("Rowkey with value {} doesn't exist in the
table", rowKey.toString());
}
} catch (IOException e) {
throw new MetaModelException(e);
@@ -141,7 +141,7 @@ final class HBaseClient {
* @throws IllegalArgumentException when any parameter is null
* @throws MetaModelException when a {@link IOException} is caught
*/
- public void createTable(String tableName, Set<String> columnFamilies) {
+ public void createTable(final String tableName, final Set<String>
columnFamilies) {
if (tableName == null || columnFamilies == null ||
columnFamilies.isEmpty()) {
throw new IllegalArgumentException("Can't create a table without
having the tableName or columnFamilies");
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/hbase/src/main/java/org/apache/metamodel/hbase/HBaseCreateTableBuilder.java
----------------------------------------------------------------------
diff --git
a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseCreateTableBuilder.java
b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseCreateTableBuilder.java
index a7c760b..4f8865c 100644
---
a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseCreateTableBuilder.java
+++
b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseCreateTableBuilder.java
@@ -34,7 +34,7 @@ public class HBaseCreateTableBuilder extends
AbstractTableCreationBuilder<HBaseU
private Set<String> _columnFamilies;
- public HBaseCreateTableBuilder(HBaseUpdateCallback updateCallback, Schema
schema, String name) {
+ public HBaseCreateTableBuilder(final HBaseUpdateCallback updateCallback,
final Schema schema, final String name) {
this(updateCallback, schema, name, null);
}
@@ -46,8 +46,8 @@ public class HBaseCreateTableBuilder extends
AbstractTableCreationBuilder<HBaseU
* @param name
* @param columnFamilies
*/
- public HBaseCreateTableBuilder(HBaseUpdateCallback updateCallback, Schema
schema, String name,
- Set<String> columnFamilies) {
+ public HBaseCreateTableBuilder(final HBaseUpdateCallback updateCallback,
final Schema schema, final String name,
+ final Set<String> columnFamilies) {
super(updateCallback, schema, name);
if (!(schema instanceof MutableSchema)) {
throw new IllegalArgumentException("Not a mutable schema: " +
schema);
@@ -73,12 +73,12 @@ public class HBaseCreateTableBuilder extends
AbstractTableCreationBuilder<HBaseU
}
/**
- * Set the columnFamilies. This should be used when creating this object
using the
- * {@link
HBaseCreateTableBuilder#HBaseCreateTableBuilder(HBaseUpdateCallback, Schema,
String)}
+ * Set the columnFamilies. This should be used when creating this object
using the
+ * {@link
HBaseCreateTableBuilder#HBaseCreateTableBuilder(HBaseUpdateCallback, Schema,
String)}
* constructor
* @param columnFamilies
*/
- public void setColumnFamilies(Set<String> columnFamilies) {
+ public void setColumnFamilies(final Set<String> columnFamilies) {
this._columnFamilies = columnFamilies;
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRow.java
----------------------------------------------------------------------
diff --git a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRow.java
b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRow.java
index 79267da..b091ae1 100644
--- a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRow.java
+++ b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRow.java
@@ -59,6 +59,7 @@ final class HBaseRow extends AbstractRow implements Row {
}
return rowKey;
}
+
final int colonIndex = name.indexOf(':');
if (colonIndex != -1) {
byte[] family = name.substring(0, colonIndex).getBytes();
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRowDeletionBuilder.java
----------------------------------------------------------------------
diff --git
a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRowDeletionBuilder.java
b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRowDeletionBuilder.java
index 9b7f9ab..75301e3 100644
---
a/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRowDeletionBuilder.java
+++
b/hbase/src/main/java/org/apache/metamodel/hbase/HBaseRowDeletionBuilder.java
@@ -27,7 +27,7 @@ import org.apache.metamodel.schema.Table;
*/
public class HBaseRowDeletionBuilder extends AbstractRowDeletionBuilder {
- private HBaseDataContext _dataContext;
+ private final HBaseDataContext _dataContext;
private Object _key;
/**
@@ -44,7 +44,7 @@ public class HBaseRowDeletionBuilder extends
AbstractRowDeletionBuilder {
this._dataContext = dataContext;
}
- /**
+ /**
* @throws MetaModelException when value is null
*/
@Override
@@ -55,7 +55,7 @@ public class HBaseRowDeletionBuilder extends
AbstractRowDeletionBuilder {
_dataContext.getHBaseClient().deleteRow(getTable().getName(), _key);
}
- public void setKey(Object key) {
+ public void setKey(final Object key) {
this._key = key;
}
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/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 289212b..0415c12 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/CreateTableTest.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/CreateTableTest.java
@@ -18,20 +18,23 @@
*/
package org.apache.metamodel.hbase;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Set;
-import java.util.stream.Collectors;
import org.apache.metamodel.MetaModelException;
import org.apache.metamodel.schema.ImmutableSchema;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.google.common.collect.Sets;
public class CreateTableTest extends HBaseUpdateCallbackTest {
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
/**
* Check if creating table is supported
@@ -47,12 +50,11 @@ public class CreateTableTest extends
HBaseUpdateCallbackTest {
@Test
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());
- }
+
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("Not a mutable schema: " + immutableSchema);
+
+ getUpdateCallback().createTable(immutableSchema, TABLE_NAME).execute();
}
/**
@@ -60,12 +62,10 @@ public class CreateTableTest extends
HBaseUpdateCallbackTest {
*/
@Test
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());
- }
+ exception.expect(MetaModelException.class);
+ exception.expectMessage("Creating a table without columnFamilies");
+
+ getUpdateCallback().createTable(getSchema(), TABLE_NAME).execute();
}
/**
@@ -73,12 +73,10 @@ public class CreateTableTest extends
HBaseUpdateCallbackTest {
*/
@Test
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());
- }
+ exception.expect(MetaModelException.class);
+ exception.expectMessage("Creating a table without columnFamilies");
+
+ getUpdateCallback().createTable(getSchema(), TABLE_NAME,
null).execute();
}
/**
@@ -86,13 +84,11 @@ public class CreateTableTest extends
HBaseUpdateCallbackTest {
*/
@Test
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());
- }
+ exception.expect(MetaModelException.class);
+ exception.expectMessage("Creating a table without columnFamilies");
+
+ final Set<String> columnFamilies = new LinkedHashSet<String>();
+ getUpdateCallback().createTable(getSchema(), TABLE_NAME,
columnFamilies).execute();
}
/**
@@ -100,14 +96,12 @@ public class CreateTableTest extends
HBaseUpdateCallbackTest {
*/
@Test
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());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("Can't create a table without having the
tableName or columnFamilies");
+
+ final Set<String> columnFamilies = new LinkedHashSet<>();
+ columnFamilies.add("1");
+ new HBaseClient(getDataContext().getConnection()).createTable(null,
columnFamilies);
}
/**
@@ -115,12 +109,10 @@ public class CreateTableTest extends
HBaseUpdateCallbackTest {
*/
@Test
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());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("Can't create a table without having the
tableName or columnFamilies");
+
+ new HBaseClient(getDataContext().getConnection()).createTable("1",
null);
}
/**
@@ -128,13 +120,11 @@ public class CreateTableTest extends
HBaseUpdateCallbackTest {
*/
@Test
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());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("Can't create a table without having the
tableName or columnFamilies");
+
+ final Set<String> columnFamilies = new LinkedHashSet<>();
+ new HBaseClient(getDataContext().getConnection()).createTable("1",
columnFamilies);
}
/**
@@ -144,66 +134,37 @@ public class CreateTableTest extends
HBaseUpdateCallbackTest {
*/
@Test
public void testCreateTableWithoutIDColumn() throws IOException {
- final HBaseTable table = createHBaseTable(TABLE_NAME, null, CF_FOO,
CF_BAR, null);
- final LinkedHashMap<HBaseColumn, Object> row = createRow(table, null,
CF_FOO, CF_BAR, false);
- final Set<String> columnFamilies =
getColumnFamilies(getHBaseColumnsFromRow(row));
- try {
- final HBaseCreateTableBuilder hBaseCreateTableBuilder =
(HBaseCreateTableBuilder) getUpdateCallback()
- .createTable(getSchema(), TABLE_NAME);
-
- hBaseCreateTableBuilder.setColumnFamilies(columnFamilies);
- hBaseCreateTableBuilder.execute();
- checkSuccesfullyInsertedTable();
- } catch (Exception e) {
- fail("Should not get an exception (that the ID-column is
missing)");
- }
+ final HBaseCreateTableBuilder hBaseCreateTableBuilder =
(HBaseCreateTableBuilder) getUpdateCallback()
+ .createTable(getSchema(), TABLE_NAME);
+
+ hBaseCreateTableBuilder.setColumnFamilies(Sets.newHashSet(CF_FOO,
CF_BAR));
+ hBaseCreateTableBuilder.execute();
+ checkSuccesfullyInsertedTable();
}
/**
* Goodflow. Create a table including the ID-Column (columnFamilies not in
constructor), should work
+ *
+ * @throws IOException
*/
@Test
- public void testSettingColumnFamiliesAfterConstrutor() {
- final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, null);
- final LinkedHashMap<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR,
- false);
- final Set<String> columnFamilies =
getColumnFamilies(getHBaseColumnsFromRow(row));
- try {
- final HBaseCreateTableBuilder hBaseCreateTableBuilder =
(HBaseCreateTableBuilder) getUpdateCallback()
- .createTable(getSchema(), TABLE_NAME);
-
- hBaseCreateTableBuilder.setColumnFamilies(columnFamilies);
- hBaseCreateTableBuilder.execute();
- checkSuccesfullyInsertedTable();
- } catch (Exception e) {
- fail("Should not get an exception");
- }
- }
+ public void testSettingColumnFamiliesAfterConstrutor() throws IOException {
+ final HBaseCreateTableBuilder hBaseCreateTableBuilder =
(HBaseCreateTableBuilder) getUpdateCallback()
+ .createTable(getSchema(), TABLE_NAME);
- /**
- * Goodflow. Create a table including the ID-Column (columnFamilies in
constructor), should work
- */
- @Test
- public void testCreateTableColumnFamiliesInConstrutor() {
- final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, null);
- final LinkedHashMap<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR,
- false);
- final Set<String> columnFamilies =
getColumnFamilies(getHBaseColumnsFromRow(row));
- try {
- getUpdateCallback().createTable(getSchema(), TABLE_NAME,
columnFamilies).execute();
- checkSuccesfullyInsertedTable();
- } catch (Exception e) {
- fail("Should not get an exception");
- }
+ hBaseCreateTableBuilder.setColumnFamilies(Sets.newHashSet(CF_FOO,
CF_BAR));
+ hBaseCreateTableBuilder.execute();
+ checkSuccesfullyInsertedTable();
}
/**
- * Creates a set of columnFamilies out of a list of hbaseColumns
+ * Goodflow. Create a table including the ID-Column (columnFamilies in
constructor), should work
*
- * @param columns
- * @return {@link Set}<{@link String}> of columnFamilies
+ * @throws IOException
*/
- private static Set<String> getColumnFamilies(List<HBaseColumn> columns) {
- return
columns.stream().map(HBaseColumn::getColumnFamily).distinct().collect(Collectors.toSet());
+ @Test
+ public void testCreateTableColumnFamiliesInConstrutor() throws IOException
{
+ getUpdateCallback().createTable(getSchema(), TABLE_NAME,
Sets.newHashSet(CF_FOO, CF_BAR)).execute();
+ checkSuccesfullyInsertedTable();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/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 7b7eeab..7aeb938 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/DeleteRowTest.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/DeleteRowTest.java
@@ -21,14 +21,18 @@ package org.apache.metamodel.hbase;
import static org.junit.Assert.*;
import java.io.IOException;
-import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import org.apache.metamodel.MetaModelException;
import org.apache.metamodel.schema.MutableTable;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class DeleteRowTest extends HBaseUpdateCallbackTest {
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
/**
* Delete is supported
@@ -44,12 +48,11 @@ public class DeleteRowTest extends HBaseUpdateCallbackTest {
@Test
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());
- }
+
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("Not an HBase table: " + mutableTable);
+
+ getUpdateCallback().deleteFrom(mutableTable);
}
/**
@@ -59,14 +62,11 @@ public class DeleteRowTest extends HBaseUpdateCallbackTest {
*/
@Test
public void testHBaseClientNullAtBuilder() throws IOException {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- new HBaseRowDeletionBuilder(null, existingTable);
- fail("Should get an exception that hBaseClient can't be null.");
- } catch (IllegalArgumentException e) {
- assertEquals("hBaseClient cannot be null", e.getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("hBaseClient cannot be null");
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ new HBaseRowDeletionBuilder(null, existingTable);
}
/**
@@ -76,14 +76,12 @@ public class DeleteRowTest extends HBaseUpdateCallbackTest {
*/
@Test
public void testNotSettingRowkey() throws IOException {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- getUpdateCallback().deleteFrom(existingTable).execute();
- fail("Should get an exception that the columnFamily doesn't
exist.");
- } catch (MetaModelException e) {
- assertEquals("Key cannot be null", e.getMessage());
- }
+ exception.expect(MetaModelException.class);
+ exception.expectMessage("Key cannot be null");
+
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ getUpdateCallback().deleteFrom(existingTable).execute();
}
/**
@@ -91,12 +89,10 @@ public class DeleteRowTest extends HBaseUpdateCallbackTest {
*/
@Test
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());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("Can't delete a row without having tableName
or rowKey");
+
+ new HBaseClient(getDataContext().getConnection()).deleteRow(null, new
String("1"));
}
/**
@@ -104,78 +100,69 @@ public class DeleteRowTest extends
HBaseUpdateCallbackTest {
*/
@Test
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());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("Can't delete a row without having tableName
or rowKey");
+
+ new
HBaseClient(getDataContext().getConnection()).deleteRow("tableName", null);
}
/**
* Goodflow. Deleting a row, that doesn't exist, should not throw an
exception
+ *
+ * @throws IOException
*/
@Test
- public void testDeletingNotExistingRow() {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
-
- checkRows(false, false);
- final HBaseRowDeletionBuilder rowDeletionBuilder =
(HBaseRowDeletionBuilder) getUpdateCallback().deleteFrom(
- existingTable);
- rowDeletionBuilder.setKey(RK_1);
- rowDeletionBuilder.execute();
- checkRows(false, false);
- } catch (Exception e) {
- fail("Should not get an exception that the row doesn't exist.");
- }
+ public void testDeletingNotExistingRow() throws IOException {
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+
+ checkRows(false, false);
+ final HBaseRowDeletionBuilder rowDeletionBuilder =
(HBaseRowDeletionBuilder) getUpdateCallback().deleteFrom(
+ existingTable);
+ rowDeletionBuilder.setKey(RK_1);
+ rowDeletionBuilder.execute();
+ checkRows(false, false);
}
/**
* Goodflow. Deleting a row, which has an empty rowKey value, should not
throw an exception
+ *
+ * @throws IOException
*/
@Test
- public void testUsingAnEmptyRowKeyValue() {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
-
- checkRows(false, false);
- final HBaseRowDeletionBuilder rowDeletionBuilder =
(HBaseRowDeletionBuilder) getUpdateCallback().deleteFrom(
- existingTable);
- rowDeletionBuilder.setKey("");
- rowDeletionBuilder.execute();
- checkRows(false, false);
- } catch (Exception e) {
- fail("Should not get an exception that the rowkey is empty.");
- }
+ public void testUsingAnEmptyRowKeyValue() throws IOException {
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+
+ checkRows(false, false);
+ final HBaseRowDeletionBuilder rowDeletionBuilder =
(HBaseRowDeletionBuilder) getUpdateCallback().deleteFrom(
+ existingTable);
+ rowDeletionBuilder.setKey("");
+ rowDeletionBuilder.execute();
+ checkRows(false, false);
}
/**
* Goodflow. Deleting a row succesfully.
+ *
+ * @throws IOException
*/
@Test
- public void testDeleteRowSuccesfully() {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR, false);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
-
- checkRows(false, false);
- final HBaseRowInsertionBuilder rowInsertionBuilder =
getUpdateCallback().insertInto(existingTable, columns);
- setValuesInInsertionBuilder(row, rowInsertionBuilder);
- rowInsertionBuilder.execute();
- checkRows(true, false);
- final HBaseRowDeletionBuilder rowDeletionBuilder =
(HBaseRowDeletionBuilder) getUpdateCallback().deleteFrom(
- existingTable);
- rowDeletionBuilder.setKey(RK_1);
- rowDeletionBuilder.execute();
- checkRows(false, false);
- } catch (Exception e) {
- fail("Should not get an exception on deleting a row.");
- }
+ public void testDeleteRowSuccesfully() throws IOException {
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(existingTable,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+
+ checkRows(false, false);
+ final HBaseRowInsertionBuilder rowInsertionBuilder =
getUpdateCallback().insertInto(existingTable, columns);
+ setValuesInInsertionBuilder(row, rowInsertionBuilder);
+ rowInsertionBuilder.execute();
+ checkRows(true, false);
+ final HBaseRowDeletionBuilder rowDeletionBuilder =
(HBaseRowDeletionBuilder) getUpdateCallback().deleteFrom(
+ existingTable);
+ rowDeletionBuilder.setKey(RK_1);
+ rowDeletionBuilder.execute();
+ checkRows(false, false);
}
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/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 70ad3f8..e3493e9 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/DropTableTest.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/DropTableTest.java
@@ -25,16 +25,20 @@ import java.io.IOException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.metamodel.MetaModelException;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class DropTableTest extends HBaseUpdateCallbackTest {
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
/**
* Check if drop table is supported
*/
@Test
public void testDropTableSupported() {
- assertTrue(getUpdateCallback().isDropTableSupported());
+ assertTrue(getUpdateCallback().isDropTableSupported());
}
/**
@@ -42,13 +46,11 @@ public class DropTableTest extends HBaseUpdateCallbackTest {
*/
@Test
public void testDropTableThatDoesntExist() {
- try {
- final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, null);
- getUpdateCallback().dropTable(table).execute();
- fail("Should get an exception that the table doesn't exist in
the datastore");
- } catch (MetaModelException e) {
- assertEquals("Trying to delete a table that doesn't exist in
the datastore.", e.getMessage());
- }
+ exception.expect(MetaModelException.class);
+ exception.expectMessage("Trying to delete a table that doesn't exist
in the datastore.");
+
+ final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR);
+ getUpdateCallback().dropTable(table).execute();
}
/**
@@ -56,29 +58,24 @@ public class DropTableTest extends HBaseUpdateCallbackTest {
*/
@Test
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());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("Can't drop a table without having the
tableName");
+
+ new HBaseClient(getDataContext().getConnection()).dropTable(null);
}
/**
- * Goodflow. Droping a table succesfully.
+ * Goodflow. Dropping a table successfully.
+ *
* @throws IOException
*/
@Test
public void testDropTableSuccesfully() throws IOException {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- getUpdateCallback().dropTable(existingTable).execute();
- try (final Admin admin = getDataContext().getAdmin()) {
-
assertFalse(admin.tableExists(TableName.valueOf(TABLE_NAME)));
- }
- } catch (Exception e) {
- fail("Should not get an exception that the table doesn't exist
in the datastore");
- }
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ getUpdateCallback().dropTable(existingTable).execute();
+ try (final Admin admin = getDataContext().getAdmin()) {
+ assertFalse(admin.tableExists(TableName.valueOf(TABLE_NAME)));
+ }
}
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/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 785fdab..58e60cc 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/HBaseTestCase.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/HBaseTestCase.java
@@ -96,7 +96,8 @@ public abstract class HBaseTestCase {
}
/**
- * Get's the test configuration file. An example file can be found at the
root folder of this project.
+ * Gets the test configuration file. An example file can be found at the
root folder of this project.
+ *
* @return Location of the configuration file.
*/
protected String getPropertyFilePath() {
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/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 425100f..0d279b8 100644
---
a/hbase/src/test/java/org/apache/metamodel/hbase/HBaseUpdateCallbackTest.java
+++
b/hbase/src/test/java/org/apache/metamodel/hbase/HBaseUpdateCallbackTest.java
@@ -22,10 +22,13 @@ import static org.junit.Assert.*;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
@@ -38,13 +41,9 @@ import org.apache.metamodel.schema.Table;
import org.apache.metamodel.util.SimpleTableDef;
import org.junit.After;
import org.junit.Before;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public abstract class HBaseUpdateCallbackTest extends HBaseTestCase {
- private static final Logger logger =
LoggerFactory.getLogger(HBaseClient.class);
-
private HBaseUpdateCallback updateCallback;
private MutableSchema schema;
@@ -63,10 +62,12 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
}
/**
- * Drop the table if it exists.
- * After that check in the schema and the datastore if the actions have
been executed succesfully.
+ * Drop the table if it exists. After that check in the schema and the
datastore if the actions have been executed
+ * successfully.
+ *
+ * @throws IOException
*/
- protected void dropTableIfItExists() {
+ protected void dropTableIfItExists() throws IOException {
if (schema != null) {
final Table table = schema.getTableByName(TABLE_NAME);
if (table != null) {
@@ -76,16 +77,14 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
// Check in the datastore
try (final Admin admin = getDataContext().getAdmin()) {
assertFalse(admin.tableExists(TableName.valueOf(TABLE_NAME)));
- } catch (IOException e) {
- fail("Should not an exception checking if the table
exists");
}
}
}
}
/**
- * Check if the table has been inserted succesfully.
- * Checks are performed in the schema and the datastore.
+ * Check if the table has been inserted successfully. Checks are performed
in the schema and the datastore.
+ *
* @throws IOException because the admin object needs to be created
*/
protected void checkSuccesfullyInsertedTable() throws IOException {
@@ -94,8 +93,6 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
// Check in the datastore
try (final Admin admin = getDataContext().getAdmin()) {
assertTrue(admin.tableExists(TableName.valueOf(TABLE_NAME)));
- } catch (IOException e) {
- fail("Should not an exception checking if the table exists");
}
}
@@ -110,7 +107,7 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
*/
protected HBaseTable createAndAddTableToDatastore(final String tableName,
final String idColumn,
final String columnFamily1, final String columnFamily2) throws
IOException {
- final LinkedHashSet<String> columnFamilies = new LinkedHashSet<>();
+ final Set<String> columnFamilies = new LinkedHashSet<>();
columnFamilies.add(idColumn);
columnFamilies.add(columnFamily1);
columnFamilies.add(columnFamily2);
@@ -128,25 +125,25 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
* @param columnFamily3 columnFamily 3 is not required and can be used to
test errors
* @return created {@link HBaseTable}
*/
- protected HBaseTable createHBaseTable(final String tableName, final String
idColumn, final String columnFamily1,
- final String columnFamily2, final String columnFamily3) {
+ protected HBaseTable createHBaseTable(final String tableName, final String
idColumn,
+ final String... columnFamilies) {
String[] columnNames;
- ColumnType[] columnTypes;
- if (idColumn == null && columnFamily3 == null) {
- columnNames = new String[] { columnFamily1, columnFamily2 };
- columnTypes = new ColumnType[] { ColumnType.STRING,
ColumnType.STRING };
- } else if (idColumn != null && columnFamily3 == null) {
- columnNames = new String[] { idColumn, columnFamily1,
columnFamily2 };
- columnTypes = new ColumnType[] { ColumnType.STRING,
ColumnType.STRING, ColumnType.STRING };
- } else if (idColumn == null && columnFamily3 != null) {
- columnNames = new String[] { columnFamily1, columnFamily2,
columnFamily3 };
- columnTypes = new ColumnType[] { ColumnType.STRING,
ColumnType.STRING, ColumnType.STRING };
+ if (idColumn == null) {
+ columnNames = columnFamilies;
} else {
- columnNames = new String[] { idColumn, columnFamily1,
columnFamily2, columnFamily3 };
- columnTypes = new ColumnType[] { ColumnType.STRING,
ColumnType.STRING, ColumnType.STRING,
- ColumnType.STRING };
+ columnNames = new String[columnFamilies.length + 1];
+
+ columnNames[0] = idColumn;
+
+ for (int i = 0; i < columnFamilies.length; i++) {
+ columnNames[i + 1] = columnFamilies[i];
+ }
}
+
+ ColumnType[] columnTypes = new ColumnType[columnNames.length];
+ Arrays.fill(columnTypes, ColumnType.STRING);
+
final SimpleTableDef tableDef = new SimpleTableDef(tableName,
columnNames, columnTypes);
return new HBaseTable(getDataContext(), tableDef, schema,
ColumnType.STRING);
}
@@ -160,9 +157,9 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
* @param qualifiersNull true will create all {@link HBaseColumn}'s with
qualifier null
* @return {@link LinkedHashMap}<{@link HBaseColumn}, {@link Object}>
*/
- protected static LinkedHashMap<HBaseColumn, Object> createRow(final
HBaseTable table, final String idColumn,
+ protected static Map<HBaseColumn, Object> createRow(final HBaseTable
table, final String idColumn,
final String columnFamily1, final String columnFamily2, final
boolean qualifiersNull) {
- final LinkedHashMap<HBaseColumn, Object> map = new LinkedHashMap<>();
+ final Map<HBaseColumn, Object> map = new LinkedHashMap<>();
// Columns
final ArrayList<HBaseColumn> columns = new ArrayList<>();
@@ -204,10 +201,8 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
* @param row {@link LinkedHashMap}<{@link HBaseColumn}, {@link Object}>
* @return {@link List}<{@link HBaseColumn}>
*/
- protected static List<HBaseColumn> getHBaseColumnsFromRow(final
LinkedHashMap<HBaseColumn, Object> row) {
- final List<HBaseColumn> columns = new ArrayList<>();
- columns.addAll(row.keySet());
- return columns;
+ protected static List<HBaseColumn> getHBaseColumnsFromRow(final
Map<HBaseColumn, Object> row) {
+ return row.keySet().stream().collect(Collectors.toList());
}
/**
@@ -216,7 +211,7 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
* @param rowInsertionBuilder insertionBuilder to be set
* @param enoughMatchingValues if true, the amount of columns match the
amount of values
*/
- protected void setValuesInInsertionBuilder(final
LinkedHashMap<HBaseColumn, Object> row,
+ protected void setValuesInInsertionBuilder(final Map<HBaseColumn, Object>
row,
final HBaseRowInsertionBuilder rowInsertionBuilder) {
int i = 0;
for (Object value : row.values()) {
@@ -225,12 +220,6 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
}
}
- protected Collection<Object> getToLittleValues(final
LinkedHashMap<HBaseColumn, Object> row) {
- Collection<Object> values = row.values();
- values.remove(V_123_BYTE_ARRAY);
- return values;
- }
-
/**
* Checks that the table does or doesn't have rows, depending on the
rowsExists parameter
* @param rowsExist true, check that the rows exists. false, check that
the result is empty.
@@ -260,19 +249,6 @@ public abstract class HBaseUpdateCallbackTest extends
HBaseTestCase {
}
}
- /**
- * Warn that the test(method) of a class is not executed, because the
test-file hasn't been set.
- * See {@link HBaseTestCase#getPropertyFilePath}
- * @param className
- * @param methodName
- */
- protected void warnAboutANotExecutedTest(String className, String
methodName) {
- String logWarning = "Test \"" + className + "#" + methodName
- + "()\" is not executed, because the HBasetest is not
configured.";
- System.err.println(logWarning);
- logger.warn(logWarning);
- }
-
protected HBaseUpdateCallback getUpdateCallback() {
return updateCallback;
}
http://git-wip-us.apache.org/repos/asf/metamodel/blob/5313a492/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 82ac9d8..61e8f9c 100644
--- a/hbase/src/test/java/org/apache/metamodel/hbase/InsertRowTest.java
+++ b/hbase/src/test/java/org/apache/metamodel/hbase/InsertRowTest.java
@@ -23,14 +23,18 @@ import static org.junit.Assert.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import org.apache.metamodel.MetaModelException;
import org.apache.metamodel.schema.MutableTable;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class InsertRowTest extends HBaseUpdateCallbackTest {
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
/**
* Check if inserting into a table is supported
@@ -49,14 +53,12 @@ public class InsertRowTest extends HBaseUpdateCallbackTest {
*/
@Test
public void testOnlyUsingTableParameter() throws IOException {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ exception.expect(UnsupportedOperationException.class);
+ exception.expectMessage("We need an explicit list of columns when
inserting into an HBase table.");
+
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
CF_BAR);
- getUpdateCallback().insertInto(existingTable);
- fail("Should get an exception that this method is not supported");
- } catch (UnsupportedOperationException e) {
- assertEquals("We need an explicit list of columns when inserting
into an HBase table.", e.getMessage());
- }
+ getUpdateCallback().insertInto(existingTable);
}
/**
@@ -67,17 +69,14 @@ public class InsertRowTest extends HBaseUpdateCallbackTest {
@Test
public void testWrongTableType() throws IOException {
final MutableTable mutableTable = new MutableTable();
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR, false);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
- getUpdateCallback().insertInto(mutableTable, columns);
- fail("Should get an exception that the type of the table is
wrong.");
- } catch (IllegalArgumentException e) {
- assertEquals("Not an HBase table: " + mutableTable,
e.getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("Not an HBase table: " + mutableTable);
+
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(existingTable,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+ getUpdateCallback().insertInto(mutableTable, columns);
}
/**
@@ -87,14 +86,12 @@ public class InsertRowTest extends HBaseUpdateCallbackTest {
*/
@Test
public void testColumnsNullAtUpdateCallBack() throws IOException {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- getUpdateCallback().insertInto(existingTable, null);
- fail("Should get an exception that the columns list is null.");
- } catch (IllegalArgumentException e) {
- assertEquals("The hbaseColumns list is null or empty",
e.getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("The hbaseColumns list is null or empty");
+
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ getUpdateCallback().insertInto(existingTable, null);
}
/**
@@ -104,14 +101,11 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
*/
@Test
public void testColumnsEmptyAtUpdateCallBack() throws IOException {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- getUpdateCallback().insertInto(existingTable, new
ArrayList<HBaseColumn>());
- fail("Should get an exception that the columns list is empty.");
- } catch (IllegalArgumentException e) {
- assertEquals("The hbaseColumns list is null or empty",
e.getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("The hbaseColumns list is null or empty");
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ getUpdateCallback().insertInto(existingTable, new
ArrayList<HBaseColumn>());
}
/**
@@ -121,20 +115,17 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
*/
@Test
public void testTableThatDoesntExist() throws IOException {
- final HBaseTable wrongTable = createHBaseTable("NewTableNotInSchema",
HBaseDataContext.FIELD_ID, "cf1", "cf2",
- null);
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR, false);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
- getUpdateCallback().insertInto(wrongTable, columns);
- fail("Should get an exception that the table isn't in the
schema.");
- } catch (MetaModelException e) {
- assertEquals("Trying to insert data into table: " +
wrongTable.getName() + ", which doesn't exist yet", e
- .getMessage());
- }
+ final HBaseTable wrongTable = createHBaseTable("NewTableNotInSchema",
HBaseDataContext.FIELD_ID, "cf1", "cf2");
+
+ exception.expect(MetaModelException.class);
+ exception.expectMessage("Trying to insert data into table: " +
wrongTable.getName()
+ + ", which doesn't exist yet");
+
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(existingTable,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+ getUpdateCallback().insertInto(wrongTable, columns);
}
/**
@@ -144,16 +135,14 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
*/
@Test
public void testIDColumnDoesntExistInColumnsArray() throws IOException {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ exception.expect(MetaModelException.class);
+ exception.expectMessage("The ID-Column was not found");
+
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, null, CF_FOO, CF_BAR, false);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
- getUpdateCallback().insertInto(existingTable, columns);
- fail("Should get an exception that ID-column doesn't exist.");
- } catch (MetaModelException e) {
- assertEquals("The ID-Column was not found", e.getMessage());
- }
+ final Map<HBaseColumn, Object> row = createRow(existingTable, null,
CF_FOO, CF_BAR, false);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+ getUpdateCallback().insertInto(existingTable, columns);
}
/**
@@ -164,20 +153,18 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
@Test
public void testColumnFamilyDoesntExistsBecauseItsNull() throws
IOException {
final String wrongColumnFamily = "wrongColumnFamily";
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR, false);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
- final HBaseTable wrongTable = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO,
- wrongColumnFamily, null);
- getUpdateCallback().insertInto(wrongTable, columns);
- fail("Should get an exception that the columnFamily doesn't
exist.");
- } catch (MetaModelException e) {
- assertEquals(String.format("ColumnFamily: %s doesn't exist in the
schema of the table", wrongColumnFamily),
- e.getMessage());
- }
+
+ exception.expect(MetaModelException.class);
+ exception.expectMessage(String.format("ColumnFamily: %s doesn't exist
in the schema of the table",
+ wrongColumnFamily));
+
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(existingTable,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+ final HBaseTable wrongTable = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO,
+ wrongColumnFamily);
+ getUpdateCallback().insertInto(wrongTable, columns);
}
/**
@@ -188,20 +175,18 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
@Test
public void testColumnFamilyDoesntExistsBecauseItsNew() throws IOException
{
final String wrongColumnFamily = "newColumnFamily";
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR, false);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
- final HBaseTable wrongTable = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR,
- wrongColumnFamily);
- getUpdateCallback().insertInto(wrongTable, columns);
- fail("Should get an exception that the columnFamily doesn't
exist.");
- } catch (MetaModelException e) {
- assertEquals(String.format("ColumnFamily: %s doesn't exist in the
schema of the table", wrongColumnFamily),
- e.getMessage());
- }
+
+ exception.expect(MetaModelException.class);
+ exception.expectMessage(String.format("ColumnFamily: %s doesn't exist
in the schema of the table",
+ wrongColumnFamily));
+
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(existingTable,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+ final HBaseTable wrongTable = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR,
+ wrongColumnFamily);
+ getUpdateCallback().insertInto(wrongTable, columns);
}
/**
@@ -209,18 +194,15 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
*/
@Test
public void testCreatingTheHBaseClientWithTableNameNull() {
- try {
- final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, null);
- final LinkedHashMap<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR,
- false);
- final HBaseColumn[] columns =
convertToHBaseColumnsArray(getHBaseColumnsFromRow(row));
- final Object[] values = new String[] { "Values" };
- new HBaseClient(getDataContext().getConnection()).insertRow(null,
columns, values, 0);
- fail("Should get an exception that tableName is null");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't insert a row without having (correct)
tableName, columns, values or indexOfIdColumn", e
- .getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage(
+ "Can't insert a row without having (correct) tableName,
columns, values or indexOfIdColumn");
+
+ final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final HBaseColumn[] columns =
convertToHBaseColumnsArray(getHBaseColumnsFromRow(row));
+ final Object[] values = new String[] { "Values" };
+ new HBaseClient(getDataContext().getConnection()).insertRow(null,
columns, values, 0);
}
/**
@@ -228,14 +210,12 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
*/
@Test
public void testCreatingTheHBaseClientWithColumnsNull() {
- try {
- final Object[] values = new String[] { "Values" };
- new
HBaseClient(getDataContext().getConnection()).insertRow("tableName", null,
values, 0);
- fail("Should get an exception that columns is null");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't insert a row without having (correct)
tableName, columns, values or indexOfIdColumn", e
- .getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage(
+ "Can't insert a row without having (correct) tableName,
columns, values or indexOfIdColumn");
+
+ final Object[] values = new String[] { "Values" };
+ new
HBaseClient(getDataContext().getConnection()).insertRow("tableName", null,
values, 0);
}
/**
@@ -243,17 +223,14 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
*/
@Test
public void testCreatingTheHBaseClientWithValuesNull() {
- try {
- final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, null);
- final LinkedHashMap<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR,
- false);
- final HBaseColumn[] columns =
convertToHBaseColumnsArray(getHBaseColumnsFromRow(row));
- new
HBaseClient(getDataContext().getConnection()).insertRow(table.getName(),
columns, null, 0);
- fail("Should get an exception that values is null");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't insert a row without having (correct)
tableName, columns, values or indexOfIdColumn", e
- .getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage(
+ "Can't insert a row without having (correct) tableName,
columns, values or indexOfIdColumn");
+
+ final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final HBaseColumn[] columns =
convertToHBaseColumnsArray(getHBaseColumnsFromRow(row));
+ new
HBaseClient(getDataContext().getConnection()).insertRow(table.getName(),
columns, null, 0);
}
/**
@@ -261,18 +238,15 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
*/
@Test
public void testCreatingTheHBaseClientWithIndexOfIdColumnOutOfBounce() {
- try {
- final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, null);
- final LinkedHashMap<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR,
- false);
- final HBaseColumn[] columns =
convertToHBaseColumnsArray(getHBaseColumnsFromRow(row));
- final Object[] values = new String[] { "Values" };
- new
HBaseClient(getDataContext().getConnection()).insertRow(table.getName(),
columns, values, 10);
- fail("Should get an exception that the indexOfIdColumn is
incorrect");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't insert a row without having (correct)
tableName, columns, values or indexOfIdColumn", e
- .getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage(
+ "Can't insert a row without having (correct) tableName,
columns, values or indexOfIdColumn");
+
+ final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final HBaseColumn[] columns =
convertToHBaseColumnsArray(getHBaseColumnsFromRow(row));
+ final Object[] values = new String[] { "Values" };
+ new
HBaseClient(getDataContext().getConnection()).insertRow(table.getName(),
columns, values, 10);
}
/**
@@ -280,102 +254,93 @@ public class InsertRowTest extends
HBaseUpdateCallbackTest {
*/
@Test
public void testCreatingTheHBaseClientWithRowKeyNull() {
- try {
- final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, null);
- final LinkedHashMap<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR,
- false);
- final HBaseColumn[] columns =
convertToHBaseColumnsArray(getHBaseColumnsFromRow(row));
- final Object[] values = new String[] { null };
- new
HBaseClient(getDataContext().getConnection()).insertRow(table.getName(),
columns, values, 0);
- fail("Should get an exception that the indexOfIdColumn is
incorrect");
- } catch (IllegalArgumentException e) {
- assertEquals("Can't insert a row without having (correct)
tableName, columns, values or indexOfIdColumn", e
- .getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage(
+ "Can't insert a row without having (correct) tableName,
columns, values or indexOfIdColumn");
+
+ final HBaseTable table = createHBaseTable(TABLE_NAME,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(table,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final HBaseColumn[] columns =
convertToHBaseColumnsArray(getHBaseColumnsFromRow(row));
+ final Object[] values = new String[] { null };
+ new
HBaseClient(getDataContext().getConnection()).insertRow(table.getName(),
columns, values, 0);
}
/**
* Inserting a row without setting enough values directly on the
HBaseClient, should throw exception.
* NOTE: This exception is already prevented when using the {@link
HBaseRowInsertionBuilder}
- * @throws IOException
+ * @throws IOException
*/
@Test
public void testNotSettingEnoughValues() throws IOException {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR, false);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
- final Collection<Object> values = getToLittleValues(row);
- final HBaseClient hBaseClient = ((HBaseDataContext)
getUpdateCallback().getDataContext()).getHBaseClient();
- hBaseClient.insertRow(TABLE_NAME, columns.toArray(new
HBaseColumn[columns.size()]), values.toArray(
- new Object[values.size()]), 0); // TODO: find the ID-column
- fail("Should get an exception when insering directly into the
HBaseClient without having enough values.");
- } catch (IllegalArgumentException e) {
- assertEquals("The amount of columns don't match the amount of
values", e.getMessage());
- }
+ exception.expect(IllegalArgumentException.class);
+ exception.expectMessage("The amount of columns don't match the amount
of values");
+
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(existingTable,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+ final Collection<Object> values = getTooLittleValues(row);
+ final HBaseClient hBaseClient = ((HBaseDataContext)
getUpdateCallback().getDataContext()).getHBaseClient();
+ hBaseClient.insertRow(TABLE_NAME, columns.toArray(new
HBaseColumn[columns.size()]), values.toArray(
+ new Object[values.size()]), 0); // TODO: find the ID-column
+ }
+
+ private Collection<Object> getTooLittleValues(final Map<HBaseColumn,
Object> row) {
+ Collection<Object> values = row.values();
+ values.remove(V_123_BYTE_ARRAY);
+ return values;
}
/**
* Goodflow. Using an existing table and columns, should work
+ *
+ * @throws IOException
*/
@Test
- public void testInsertIntoWithoutExecute() {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR, false);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
- getUpdateCallback().insertInto(existingTable, columns);
- } catch (Exception e) {
- fail("No exception should be thrown, when inserting into an
existing table.");
- }
+ public void testInsertIntoWithoutExecute() throws IOException {
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(existingTable,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+ getUpdateCallback().insertInto(existingTable, columns);
}
/**
* Goodflow, creating a row with qualifiers null should work.
+ *
+ * @throws IOException
*/
@Test
- public void testQaulifierNull() {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR, true);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
-
- checkRows(false, true);
- final HBaseRowInsertionBuilder rowInsertionBuilder =
getUpdateCallback().insertInto(existingTable, columns);
- setValuesInInsertionBuilder(row, rowInsertionBuilder);
- rowInsertionBuilder.execute();
- checkRows(true, true);
- } catch (Exception e) {
- fail("Inserting a row without qualifiers should work.");
- }
+ public void testQaulifierNull() throws IOException {
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(existingTable,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, true);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+
+ checkRows(false, true);
+ final HBaseRowInsertionBuilder rowInsertionBuilder =
getUpdateCallback().insertInto(existingTable, columns);
+ setValuesInInsertionBuilder(row, rowInsertionBuilder);
+ rowInsertionBuilder.execute();
+ checkRows(true, true);
}
/**
* Goodflow. Inserting a row succesfully (with values set)
+ *
+ * @throws IOException
*/
@Test
- public void testInsertingSuccesfully() {
- try {
- final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR);
- final LinkedHashMap<HBaseColumn, Object> row =
createRow(existingTable, HBaseDataContext.FIELD_ID, CF_FOO,
- CF_BAR, false);
- final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
-
- checkRows(false, false);
- final HBaseRowInsertionBuilder rowInsertionBuilder =
getUpdateCallback().insertInto(existingTable, columns);
- setValuesInInsertionBuilder(row, rowInsertionBuilder);
- rowInsertionBuilder.execute();
- checkRows(true, false);
- } catch (Exception e) {
- fail("No exception should be thrown, when inserting with values.");
- }
+ public void testInsertingSuccesfully() throws IOException {
+ final HBaseTable existingTable =
createAndAddTableToDatastore(TABLE_NAME, HBaseDataContext.FIELD_ID, CF_FOO,
+ CF_BAR);
+ final Map<HBaseColumn, Object> row = createRow(existingTable,
HBaseDataContext.FIELD_ID, CF_FOO, CF_BAR, false);
+ final List<HBaseColumn> columns = getHBaseColumnsFromRow(row);
+
+ checkRows(false, false);
+ final HBaseRowInsertionBuilder rowInsertionBuilder =
getUpdateCallback().insertInto(existingTable, columns);
+ setValuesInInsertionBuilder(row, rowInsertionBuilder);
+ rowInsertionBuilder.execute();
+ checkRows(true, false);
}
/**