You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fluo.apache.org by kt...@apache.org on 2016/09/16 22:00:52 UTC
incubator-fluo git commit: removed default methods from interfaces
#770 #771 #772
Repository: incubator-fluo
Updated Branches:
refs/heads/master 0373ec549 -> 49b3abb64
removed default methods from interfaces #770 #771 #772
Project: http://git-wip-us.apache.org/repos/asf/incubator-fluo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fluo/commit/49b3abb6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fluo/tree/49b3abb6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fluo/diff/49b3abb6
Branch: refs/heads/master
Commit: 49b3abb64e463f8a6265dbe1d2ce48068fbea8fe
Parents: 0373ec5
Author: Keith Turner <kt...@apache.org>
Authored: Fri Sep 16 16:22:50 2016 -0400
Committer: Keith Turner <kt...@apache.org>
Committed: Fri Sep 16 16:22:50 2016 -0400
----------------------------------------------------------------------
.../fluo/api/client/AbstractSnapshotBase.java | 102 +++++++++
.../api/client/AbstractTransactionBase.java | 41 ++++
.../apache/fluo/api/client/SnapshotBase.java | 71 +------
.../apache/fluo/api/client/TransactionBase.java | 13 +-
.../api/client/AbstractTransactionBaseTest.java | 210 +++++++++++++++++++
.../client/TestDefaultTransactionMethods.java | 210 -------------------
.../apache/fluo/core/impl/TransactionImpl.java | 3 +-
.../fluo/core/log/TracingTransaction.java | 4 +-
.../fluo/integration/TestTransaction.java | 3 +-
9 files changed, 375 insertions(+), 282 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/49b3abb6/modules/api/src/main/java/org/apache/fluo/api/client/AbstractSnapshotBase.java
----------------------------------------------------------------------
diff --git a/modules/api/src/main/java/org/apache/fluo/api/client/AbstractSnapshotBase.java b/modules/api/src/main/java/org/apache/fluo/api/client/AbstractSnapshotBase.java
new file mode 100644
index 0000000..30b325a
--- /dev/null
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/AbstractSnapshotBase.java
@@ -0,0 +1,102 @@
+/*
+ * 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.api.client;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.data.RowColumn;
+
+/**
+ * This class provides default implementations for many of the classes in SnapshotBase. It exists to
+ * make implementing SnapshotBase easier.
+ */
+
+public abstract class AbstractSnapshotBase implements SnapshotBase {
+
+ public Bytes get(Bytes row, Column column, Bytes defaultValue) {
+ Bytes ret = get(row, column);
+ if (ret == null) {
+ return defaultValue;
+ }
+
+ return ret;
+ }
+
+ public Map<Column, Bytes> get(Bytes row, Column... columns) {
+ return get(row, ImmutableSet.copyOf(columns));
+ }
+
+ public Map<Bytes, Map<Column, Bytes>> get(Collection<Bytes> rows, Column... columns) {
+ return get(rows, ImmutableSet.copyOf(columns));
+ }
+
+ public Map<RowColumn, String> gets(Collection<RowColumn> rowColumns) {
+ Map<RowColumn, Bytes> bytesMap = get(rowColumns);
+ return Maps.transformValues(bytesMap, b -> b.toString());
+ }
+
+ public Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows,
+ Set<Column> columns) {
+ Map<Bytes, Map<Column, Bytes>> rcvs =
+ get(Collections2.transform(rows, s -> Bytes.of(s)), columns);
+ Map<String, Map<Column, String>> ret = new HashMap<>(rcvs.size());
+
+ for (Entry<Bytes, Map<Column, Bytes>> entry : rcvs.entrySet()) {
+ ret.put(entry.getKey().toString(), Maps.transformValues(entry.getValue(), b -> b.toString()));
+ }
+ return ret;
+ }
+
+ public Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows,
+ Column... columns) {
+ return gets(rows, ImmutableSet.copyOf(columns));
+ }
+
+ public String gets(CharSequence row, Column column) {
+ Bytes val = get(Bytes.of(row), column);
+ if (val == null) {
+ return null;
+ }
+ return val.toString();
+ }
+
+ public String gets(CharSequence row, Column column, String defaultValue) {
+ Bytes val = get(Bytes.of(row), column);
+ if (val == null) {
+ return defaultValue;
+ }
+
+ return val.toString();
+ }
+
+ public Map<Column, String> gets(CharSequence row, Set<Column> columns) {
+ Map<Column, Bytes> values = get(Bytes.of(row), columns);
+ return Maps.transformValues(values, b -> b.toString());
+ }
+
+ public Map<Column, String> gets(CharSequence row, Column... columns) {
+ return gets(row, ImmutableSet.copyOf(columns));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/49b3abb6/modules/api/src/main/java/org/apache/fluo/api/client/AbstractTransactionBase.java
----------------------------------------------------------------------
diff --git a/modules/api/src/main/java/org/apache/fluo/api/client/AbstractTransactionBase.java b/modules/api/src/main/java/org/apache/fluo/api/client/AbstractTransactionBase.java
new file mode 100644
index 0000000..0ffd650
--- /dev/null
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/AbstractTransactionBase.java
@@ -0,0 +1,41 @@
+/*
+ * 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.api.client;
+
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.exceptions.AlreadySetException;
+
+/**
+ * This class provides default implementations for many of the methods in TransactionBase. It exists
+ * to make implementing TransactionBase easier.
+ */
+
+public abstract class AbstractTransactionBase extends AbstractSnapshotBase implements
+ TransactionBase {
+
+ public void delete(CharSequence row, Column col) {
+ delete(Bytes.of(row), col);
+ }
+
+ public void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException {
+ set(Bytes.of(row), col, Bytes.of(value));
+ }
+
+ public void setWeakNotification(CharSequence row, Column col) {
+ setWeakNotification(Bytes.of(row), col);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/49b3abb6/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
----------------------------------------------------------------------
diff --git a/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java b/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
index 723b9c7..ac8bc40 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
@@ -16,14 +16,9 @@
package org.apache.fluo.api.client;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import java.util.Map.Entry;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
import org.apache.fluo.api.client.scanner.ScannerBuilder;
import org.apache.fluo.api.data.Bytes;
import org.apache.fluo.api.data.Column;
@@ -34,6 +29,7 @@ import org.apache.fluo.api.data.Span;
* Allows users to read from a Fluo table at a certain point in time
*
* @since 1.0.0
+ * @see AbstractSnapshotBase
*/
public interface SnapshotBase {
@@ -49,14 +45,7 @@ public interface SnapshotBase {
*
* @param defaultValue this will be returned if row+columns does not exists
*/
- default Bytes get(Bytes row, Column column, Bytes defaultValue) {
- Bytes ret = get(row, column);
- if (ret == null) {
- return defaultValue;
- }
-
- return ret;
- }
+ Bytes get(Bytes row, Column column, Bytes defaultValue);
/**
* Given a row and set of {@link Column}s, retrieves a map that contains the values at those
@@ -68,9 +57,7 @@ public interface SnapshotBase {
* Given a row and list of {@link Column}s, retrieves a map that contains the values at those
* {@link Column}s. Only columns that exist will be returned in map.
*/
- default Map<Column, Bytes> get(Bytes row, Column... columns) {
- return get(row, ImmutableSet.copyOf(columns));
- }
+ Map<Column, Bytes> get(Bytes row, Column... columns);
/**
* Given a collection of rows and set of {@link Column}s, retrieves a map that contains the values
@@ -83,9 +70,7 @@ public interface SnapshotBase {
* values at those rows and {@link Column}s. Only rows and columns that exists will be returned in
* map.
*/
- default Map<Bytes, Map<Column, Bytes>> get(Collection<Bytes> rows, Column... columns) {
- return get(rows, ImmutableSet.copyOf(columns));
- }
+ Map<Bytes, Map<Column, Bytes>> get(Collection<Bytes> rows, Column... columns);
/**
@@ -137,77 +122,43 @@ public interface SnapshotBase {
* Wrapper for {@link #get(Collection)} that uses Strings. All strings are encoded and decoded
* using UTF-8.
*/
- default Map<RowColumn, String> gets(Collection<RowColumn> rowColumns) {
- Map<RowColumn, Bytes> bytesMap = get(rowColumns);
- return Maps.transformValues(bytesMap, b -> b.toString());
- }
+ Map<RowColumn, String> gets(Collection<RowColumn> rowColumns);
/**
* Wrapper for {@link #get(Collection, Set)} that uses Strings. All strings are encoded and
* decoded using UTF-8.
*/
- default Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows,
- Set<Column> columns) {
- Map<Bytes, Map<Column, Bytes>> rcvs =
- get(Collections2.transform(rows, s -> Bytes.of(s)), columns);
- Map<String, Map<Column, String>> ret = new HashMap<>(rcvs.size());
-
- for (Entry<Bytes, Map<Column, Bytes>> entry : rcvs.entrySet()) {
- ret.put(entry.getKey().toString(), Maps.transformValues(entry.getValue(), b -> b.toString()));
- }
- return ret;
- }
+ Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows, Set<Column> columns);
/**
* Wrapper for {@link #get(Collection, Set)} that uses Strings. All strings are encoded and
* decoded using UTF-8.
*/
- default Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows,
- Column... columns) {
- return gets(rows, ImmutableSet.copyOf(columns));
- }
+ Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows, Column... columns);
/**
* Wrapper for {@link #get(Bytes, Column)} that uses Strings. All strings are encoded and decoded
* using UTF-8.
*/
- default String gets(CharSequence row, Column column) {
- Bytes val = get(Bytes.of(row), column);
- if (val == null) {
- return null;
- }
- return val.toString();
- }
+ String gets(CharSequence row, Column column);
/**
* Wrapper for {@link #get(Bytes, Column, Bytes)} that uses Strings. All strings are encoded and
* decoded using UTF-8.
*/
- default String gets(CharSequence row, Column column, String defaultValue) {
- Bytes val = get(Bytes.of(row), column);
- if (val == null) {
- return defaultValue;
- }
-
- return val.toString();
- }
+ String gets(CharSequence row, Column column, String defaultValue);
/**
* Wrapper for {@link #get(Bytes, Set)} that uses Strings. All strings are encoded and decoded
* using UTF-8.
*/
- default Map<Column, String> gets(CharSequence row, Set<Column> columns) {
- Map<Column, Bytes> values = get(Bytes.of(row), columns);
- return Maps.transformValues(values, b -> b.toString());
- }
+ Map<Column, String> gets(CharSequence row, Set<Column> columns);
/**
* Wrapper for {@link #get(Bytes, Set)} that uses Strings. All strings are encoded and decoded
* using UTF-8.
*/
- default Map<Column, String> gets(CharSequence row, Column... columns) {
- return gets(row, ImmutableSet.copyOf(columns));
- }
+ Map<Column, String> gets(CharSequence row, Column... columns);
/**
* @return transactions start timestamp allocated from Oracle.
http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/49b3abb6/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java
----------------------------------------------------------------------
diff --git a/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java b/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java
index 57a0e1e..06303b6 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java
@@ -24,6 +24,7 @@ import org.apache.fluo.api.exceptions.AlreadySetException;
* {@link SnapshotBase} to include methods for writing to Fluo.
*
* @since 1.0.0
+ * @see AbstractTransactionBase
*/
public interface TransactionBase extends SnapshotBase {
@@ -36,9 +37,7 @@ public interface TransactionBase extends SnapshotBase {
* Wrapper for {@link #delete(Bytes, Column)} that uses Strings. All String are encoded using
* UTF-8.
*/
- default void delete(CharSequence row, Column col) {
- delete(Bytes.of(row), col);
- }
+ void delete(CharSequence row, Column col);
/**
* Sets a value (in {@link Bytes}) at the given row and {@link Column}
@@ -49,9 +48,7 @@ public interface TransactionBase extends SnapshotBase {
* Wrapper for {@link #set(Bytes, Column, Bytes)} that uses Strings. All String are encoded using
* UTF-8.
*/
- default void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException {
- set(Bytes.of(row), col, Bytes.of(value));
- }
+ void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException;
/**
* Sets a weak notification at the given row and {@link Column}
@@ -62,7 +59,5 @@ public interface TransactionBase extends SnapshotBase {
* Wrapper for {@link #setWeakNotification(Bytes, Column)} that uses Strings. All String are
* encoded using UTF-8.
*/
- default void setWeakNotification(CharSequence row, Column col) {
- setWeakNotification(Bytes.of(row), col);
- }
+ void setWeakNotification(CharSequence row, Column col);
}
http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/49b3abb6/modules/api/src/test/java/org/apache/fluo/api/client/AbstractTransactionBaseTest.java
----------------------------------------------------------------------
diff --git a/modules/api/src/test/java/org/apache/fluo/api/client/AbstractTransactionBaseTest.java b/modules/api/src/test/java/org/apache/fluo/api/client/AbstractTransactionBaseTest.java
new file mode 100644
index 0000000..6e08231
--- /dev/null
+++ b/modules/api/src/test/java/org/apache/fluo/api/client/AbstractTransactionBaseTest.java
@@ -0,0 +1,210 @@
+/*
+ * 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.api.client;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.apache.fluo.api.client.scanner.ScannerBuilder;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.data.RowColumn;
+import org.apache.fluo.api.data.RowColumnValue;
+import org.apache.fluo.api.exceptions.AlreadySetException;
+import org.apache.fluo.api.exceptions.CommitException;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AbstractTransactionBaseTest {
+
+ private static class MockTransaction extends AbstractTransactionBase implements Transaction {
+
+ public Set<RowColumnValue> sets = new HashSet<>();
+ public Set<RowColumn> deletes = new HashSet<>();
+ public Set<RowColumn> weakNtfys = new HashSet<>();
+ public Map<RowColumn, Bytes> snapshot;
+
+ MockTransaction(Map<RowColumn, Bytes> snapshot) {
+ this.snapshot = snapshot;
+ }
+
+ @Override
+ public void delete(Bytes row, Column col) {
+ deletes.add(new RowColumn(row, col));
+ }
+
+ @Override
+ public void set(Bytes row, Column col, Bytes value) throws AlreadySetException {
+ sets.add(new RowColumnValue(row, col, value));
+ }
+
+ @Override
+ public void setWeakNotification(Bytes row, Column col) {
+ weakNtfys.add(new RowColumn(row, col));
+ }
+
+ @Override
+ public Bytes get(Bytes row, Column column) {
+ return snapshot.get(new RowColumn(row, column));
+ }
+
+ @Override
+ public Map<Column, Bytes> get(Bytes row, Set<Column> columns) {
+ HashMap<Column, Bytes> ret = new HashMap<Column, Bytes>();
+ for (Column column : columns) {
+ RowColumn rc = new RowColumn(row, column);
+ if (snapshot.containsKey(rc)) {
+ ret.put(column, snapshot.get(rc));
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public Map<Bytes, Map<Column, Bytes>> get(Collection<Bytes> rows, Set<Column> columns) {
+ Map<Bytes, Map<Column, Bytes>> ret = new HashMap<>();
+
+ for (Bytes row : rows) {
+ for (Column col : columns) {
+ RowColumn rc = new RowColumn(row, col);
+ if (snapshot.containsKey(rc)) {
+ ret.computeIfAbsent(row, k -> new HashMap<>()).put(col, snapshot.get(rc));
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Map<RowColumn, Bytes> get(Collection<RowColumn> rowColumns) {
+ Map<RowColumn, Bytes> ret = new HashMap<>();
+ for (RowColumn rc : rowColumns) {
+ if (snapshot.containsKey(rc)) {
+ ret.put(rc, snapshot.get(rc));
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public ScannerBuilder scanner() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getStartTimestamp() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void commit() throws CommitException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void close() {}
+
+ }
+
+ private static final Column COL1 = new Column("f1", "q1");
+ private static final Column COL2 = new Column("f1", "q2");
+
+ private Map<RowColumn, Bytes> createSnapshot() {
+ Map<RowColumn, Bytes> snap = new HashMap<>();
+ snap.put(new RowColumn("row1", COL1), Bytes.of("v1"));
+ snap.put(new RowColumn("row2", COL1), Bytes.of("v2"));
+ snap.put(new RowColumn("row2", COL2), Bytes.of("v3"));
+ snap.put(new RowColumn("row3", COL1), Bytes.of("v4"));
+ return snap;
+ }
+
+ @Test
+ public void testColumnsVarargs() {
+
+ MockTransaction tx = new MockTransaction(createSnapshot());
+ Assert
+ .assertEquals(ImmutableMap.of(COL1, Bytes.of("v1")), tx.get(Bytes.of("row1"), COL1, COL2));
+ Assert.assertEquals(ImmutableMap.of(COL1, Bytes.of("v2"), COL2, Bytes.of("v3")),
+ tx.get(Bytes.of("row2"), COL1, COL2));
+
+ Assert.assertEquals(ImmutableMap.of(COL1, "v1"), tx.gets("row1", COL1, COL2));
+ Assert.assertEquals(ImmutableMap.of(COL1, "v2", COL2, "v3"), tx.gets("row2", COL1, COL2));
+
+ Map<Bytes, Map<Column, Bytes>> ret =
+ tx.get(Arrays.asList(Bytes.of("row1"), Bytes.of("row2")), COL1, COL2);
+ Assert.assertEquals(ImmutableSet.of(Bytes.of("row1"), Bytes.of("row2")), ret.keySet());
+ Assert.assertEquals(ImmutableMap.of(COL1, Bytes.of("v1")), ret.get(Bytes.of("row1")));
+ Assert.assertEquals(ImmutableMap.of(COL1, Bytes.of("v2"), COL2, Bytes.of("v3")),
+ ret.get(Bytes.of("row2")));
+
+ Map<String, Map<Column, String>> ret2 = tx.gets(Arrays.asList("row1", "row2"), COL1, COL2);
+ Assert.assertEquals(ImmutableSet.of("row1", "row2"), ret2.keySet());
+ Assert.assertEquals(ImmutableMap.of(COL1, "v1"), ret2.get("row1"));
+ Assert.assertEquals(ImmutableMap.of(COL1, "v2", COL2, "v3"), ret2.get("row2"));
+
+ tx.close();
+ }
+
+ @Test
+ public void testGetStringMethods() {
+ MockTransaction tx = new MockTransaction(createSnapshot());
+
+ Assert.assertNull(tx.gets("row4", COL1));
+ Assert.assertEquals("v4", tx.gets("row3", COL1));
+
+ RowColumn rc1 = new RowColumn("row1", COL1);
+ RowColumn rc2 = new RowColumn("row2", COL2);
+
+ Map<RowColumn, String> ret = tx.gets(Arrays.asList(rc1, rc2));
+ Assert.assertEquals(ImmutableMap.of(rc1, "v1", rc2, "v3"), ret);
+
+ tx.close();
+ }
+
+ @Test
+ public void testMutationMethods() {
+ MockTransaction tx = new MockTransaction(createSnapshot());
+
+ tx.delete("row5", COL1);
+ tx.set("row9", COL2, "99");
+ tx.set("row8", COL2, "88");
+ tx.setWeakNotification("row5", COL2);
+
+ Assert.assertEquals(ImmutableSet.of(new RowColumn("row5", COL1)), tx.deletes);
+ Assert.assertEquals(ImmutableSet.of(new RowColumnValue("row9", COL2, "99"), new RowColumnValue(
+ "row8", COL2, "88")), tx.sets);
+ Assert.assertEquals(ImmutableSet.of(new RowColumn("row5", COL2)), tx.weakNtfys);
+
+ tx.close();
+ }
+
+ @Test
+ public void testGetDefault() {
+ MockTransaction tx = new MockTransaction(createSnapshot());
+
+ Assert.assertEquals(Bytes.of("vd"), tx.get(Bytes.of("row4"), COL1, Bytes.of("vd")));
+ Assert.assertEquals("vd", tx.gets("row4", COL1, "vd"));
+
+ tx.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/49b3abb6/modules/api/src/test/java/org/apache/fluo/api/client/TestDefaultTransactionMethods.java
----------------------------------------------------------------------
diff --git a/modules/api/src/test/java/org/apache/fluo/api/client/TestDefaultTransactionMethods.java b/modules/api/src/test/java/org/apache/fluo/api/client/TestDefaultTransactionMethods.java
deleted file mode 100644
index bbe894a..0000000
--- a/modules/api/src/test/java/org/apache/fluo/api/client/TestDefaultTransactionMethods.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * 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.api.client;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import org.apache.fluo.api.client.scanner.ScannerBuilder;
-import org.apache.fluo.api.data.Bytes;
-import org.apache.fluo.api.data.Column;
-import org.apache.fluo.api.data.RowColumn;
-import org.apache.fluo.api.data.RowColumnValue;
-import org.apache.fluo.api.exceptions.AlreadySetException;
-import org.apache.fluo.api.exceptions.CommitException;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestDefaultTransactionMethods {
-
- private static class MockTransaction implements Transaction {
-
- public Set<RowColumnValue> sets = new HashSet<>();
- public Set<RowColumn> deletes = new HashSet<>();
- public Set<RowColumn> weakNtfys = new HashSet<>();
- public Map<RowColumn, Bytes> snapshot;
-
- MockTransaction(Map<RowColumn, Bytes> snapshot) {
- this.snapshot = snapshot;
- }
-
- @Override
- public void delete(Bytes row, Column col) {
- deletes.add(new RowColumn(row, col));
- }
-
- @Override
- public void set(Bytes row, Column col, Bytes value) throws AlreadySetException {
- sets.add(new RowColumnValue(row, col, value));
- }
-
- @Override
- public void setWeakNotification(Bytes row, Column col) {
- weakNtfys.add(new RowColumn(row, col));
- }
-
- @Override
- public Bytes get(Bytes row, Column column) {
- return snapshot.get(new RowColumn(row, column));
- }
-
- @Override
- public Map<Column, Bytes> get(Bytes row, Set<Column> columns) {
- HashMap<Column, Bytes> ret = new HashMap<Column, Bytes>();
- for (Column column : columns) {
- RowColumn rc = new RowColumn(row, column);
- if (snapshot.containsKey(rc)) {
- ret.put(column, snapshot.get(rc));
- }
- }
- return ret;
- }
-
- @Override
- public Map<Bytes, Map<Column, Bytes>> get(Collection<Bytes> rows, Set<Column> columns) {
- Map<Bytes, Map<Column, Bytes>> ret = new HashMap<>();
-
- for (Bytes row : rows) {
- for (Column col : columns) {
- RowColumn rc = new RowColumn(row, col);
- if (snapshot.containsKey(rc)) {
- ret.computeIfAbsent(row, k -> new HashMap<>()).put(col, snapshot.get(rc));
- }
- }
- }
-
- return ret;
- }
-
- @Override
- public Map<RowColumn, Bytes> get(Collection<RowColumn> rowColumns) {
- Map<RowColumn, Bytes> ret = new HashMap<>();
- for (RowColumn rc : rowColumns) {
- if (snapshot.containsKey(rc)) {
- ret.put(rc, snapshot.get(rc));
- }
- }
- return ret;
- }
-
- @Override
- public ScannerBuilder scanner() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public long getStartTimestamp() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void commit() throws CommitException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void close() {}
-
- }
-
- private static final Column COL1 = new Column("f1", "q1");
- private static final Column COL2 = new Column("f1", "q2");
-
- private Map<RowColumn, Bytes> createSnapshot() {
- Map<RowColumn, Bytes> snap = new HashMap<>();
- snap.put(new RowColumn("row1", COL1), Bytes.of("v1"));
- snap.put(new RowColumn("row2", COL1), Bytes.of("v2"));
- snap.put(new RowColumn("row2", COL2), Bytes.of("v3"));
- snap.put(new RowColumn("row3", COL1), Bytes.of("v4"));
- return snap;
- }
-
- @Test
- public void testColumnsVarargs() {
-
- MockTransaction tx = new MockTransaction(createSnapshot());
- Assert
- .assertEquals(ImmutableMap.of(COL1, Bytes.of("v1")), tx.get(Bytes.of("row1"), COL1, COL2));
- Assert.assertEquals(ImmutableMap.of(COL1, Bytes.of("v2"), COL2, Bytes.of("v3")),
- tx.get(Bytes.of("row2"), COL1, COL2));
-
- Assert.assertEquals(ImmutableMap.of(COL1, "v1"), tx.gets("row1", COL1, COL2));
- Assert.assertEquals(ImmutableMap.of(COL1, "v2", COL2, "v3"), tx.gets("row2", COL1, COL2));
-
- Map<Bytes, Map<Column, Bytes>> ret =
- tx.get(Arrays.asList(Bytes.of("row1"), Bytes.of("row2")), COL1, COL2);
- Assert.assertEquals(ImmutableSet.of(Bytes.of("row1"), Bytes.of("row2")), ret.keySet());
- Assert.assertEquals(ImmutableMap.of(COL1, Bytes.of("v1")), ret.get(Bytes.of("row1")));
- Assert.assertEquals(ImmutableMap.of(COL1, Bytes.of("v2"), COL2, Bytes.of("v3")),
- ret.get(Bytes.of("row2")));
-
- Map<String, Map<Column, String>> ret2 = tx.gets(Arrays.asList("row1", "row2"), COL1, COL2);
- Assert.assertEquals(ImmutableSet.of("row1", "row2"), ret2.keySet());
- Assert.assertEquals(ImmutableMap.of(COL1, "v1"), ret2.get("row1"));
- Assert.assertEquals(ImmutableMap.of(COL1, "v2", COL2, "v3"), ret2.get("row2"));
-
- tx.close();
- }
-
- @Test
- public void testGetStringMethods() {
- MockTransaction tx = new MockTransaction(createSnapshot());
-
- Assert.assertNull(tx.gets("row4", COL1));
- Assert.assertEquals("v4", tx.gets("row3", COL1));
-
- RowColumn rc1 = new RowColumn("row1", COL1);
- RowColumn rc2 = new RowColumn("row2", COL2);
-
- Map<RowColumn, String> ret = tx.gets(Arrays.asList(rc1, rc2));
- Assert.assertEquals(ImmutableMap.of(rc1, "v1", rc2, "v3"), ret);
-
- tx.close();
- }
-
- @Test
- public void testMutationMethods() {
- MockTransaction tx = new MockTransaction(createSnapshot());
-
- tx.delete("row5", COL1);
- tx.set("row9", COL2, "99");
- tx.set("row8", COL2, "88");
- tx.setWeakNotification("row5", COL2);
-
- Assert.assertEquals(ImmutableSet.of(new RowColumn("row5", COL1)), tx.deletes);
- Assert.assertEquals(ImmutableSet.of(new RowColumnValue("row9", COL2, "99"), new RowColumnValue(
- "row8", COL2, "88")), tx.sets);
- Assert.assertEquals(ImmutableSet.of(new RowColumn("row5", COL2)), tx.weakNtfys);
-
- tx.close();
- }
-
- @Test
- public void testGetDefault() {
- MockTransaction tx = new MockTransaction(createSnapshot());
-
- Assert.assertEquals(Bytes.of("vd"), tx.get(Bytes.of("row4"), COL1, Bytes.of("vd")));
- Assert.assertEquals("vd", tx.gets("row4", COL1, "vd"));
-
- tx.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/49b3abb6/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java b/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java
index 2591a57..441517a 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java
@@ -53,6 +53,7 @@ import org.apache.fluo.accumulo.iterators.PrewriteIterator;
import org.apache.fluo.accumulo.util.ColumnConstants;
import org.apache.fluo.accumulo.values.DelLockValue;
import org.apache.fluo.accumulo.values.LockValue;
+import org.apache.fluo.api.client.AbstractTransactionBase;
import org.apache.fluo.api.client.Snapshot;
import org.apache.fluo.api.client.scanner.ScannerBuilder;
import org.apache.fluo.api.data.Bytes;
@@ -81,7 +82,7 @@ import org.apache.fluo.core.util.SpanUtil;
/**
* Transaction implementation
*/
-public class TransactionImpl implements AsyncTransaction, Snapshot {
+public class TransactionImpl extends AbstractTransactionBase implements AsyncTransaction, Snapshot {
public static final byte[] EMPTY = new byte[0];
public static final Bytes EMPTY_BS = Bytes.of(EMPTY);
http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/49b3abb6/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java b/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java
index 6c52c9a..f9298de 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java
@@ -20,6 +20,7 @@ import java.util.Map;
import java.util.Set;
import com.google.common.collect.Iterators;
+import org.apache.fluo.api.client.AbstractTransactionBase;
import org.apache.fluo.api.client.Snapshot;
import org.apache.fluo.api.client.scanner.ScannerBuilder;
import org.apache.fluo.api.config.FluoConfiguration;
@@ -36,7 +37,8 @@ import org.apache.fluo.core.util.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class TracingTransaction implements AsyncTransaction, Snapshot {
+public class TracingTransaction extends AbstractTransactionBase implements AsyncTransaction,
+ Snapshot {
private static final Logger log = LoggerFactory.getLogger(FluoConfiguration.TRANSACTION_PREFIX);
private static final Logger collisionLog = LoggerFactory
http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/49b3abb6/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java
----------------------------------------------------------------------
diff --git a/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java b/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java
index 6a214c8..ac2a774 100644
--- a/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java
+++ b/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java
@@ -30,6 +30,7 @@ import org.apache.accumulo.core.data.Key;
import org.apache.fluo.accumulo.iterators.NotificationIterator;
import org.apache.fluo.accumulo.util.ColumnConstants;
import org.apache.fluo.accumulo.util.NotificationUtil;
+import org.apache.fluo.api.client.AbstractTransactionBase;
import org.apache.fluo.api.client.TransactionBase;
import org.apache.fluo.api.client.scanner.ScannerBuilder;
import org.apache.fluo.api.data.Bytes;
@@ -50,7 +51,7 @@ import org.apache.fluo.core.util.ByteUtil;
import org.apache.fluo.core.util.SpanUtil;
import org.apache.hadoop.io.Text;
-public class TestTransaction implements TransactionBase {
+public class TestTransaction extends AbstractTransactionBase implements TransactionBase {
private TransactionImpl tx;
private Environment env;