You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2016/12/14 06:47:49 UTC
hbase git commit: HBASE-17313 Add BufferedMutatorParams#clone method
(Joep Rottinghuis)
Repository: hbase
Updated Branches:
refs/heads/master 68ce3f1e3 -> a73b0b3e6
HBASE-17313 Add BufferedMutatorParams#clone method (Joep Rottinghuis)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/a73b0b3e
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/a73b0b3e
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/a73b0b3e
Branch: refs/heads/master
Commit: a73b0b3e6d42c3f7fd0c3a0d9f80c2763a6cf069
Parents: 68ce3f1
Author: Michael Stack <st...@apache.org>
Authored: Tue Dec 13 22:47:41 2016 -0800
Committer: Michael Stack <st...@apache.org>
Committed: Tue Dec 13 22:47:41 2016 -0800
----------------------------------------------------------------------
.../hbase/client/BufferedMutatorParams.java | 16 +-
.../hbase/client/TestBufferedMutatorParams.java | 154 +++++++++++++++++++
2 files changed, 169 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/a73b0b3e/hbase-client/src/main/java/org/apache/hadoop/hbase/client/BufferedMutatorParams.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/BufferedMutatorParams.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/BufferedMutatorParams.java
index aacb5f3..fa1fa86 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/BufferedMutatorParams.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/BufferedMutatorParams.java
@@ -126,4 +126,18 @@ public class BufferedMutatorParams {
this.listener = listener;
return this;
}
-}
\ No newline at end of file
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#clone()
+ */
+ public BufferedMutatorParams clone() {
+ BufferedMutatorParams clone = new BufferedMutatorParams(this.tableName);
+ clone.writeBufferSize = this.writeBufferSize;
+ clone.maxKeyValueSize = maxKeyValueSize;
+ clone.pool = this.pool;
+ clone.listener = this.listener;
+ return clone;
+ }
+}
http://git-wip-us.apache.org/repos/asf/hbase/blob/a73b0b3e/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestBufferedMutatorParams.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestBufferedMutatorParams.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestBufferedMutatorParams.java
new file mode 100644
index 0000000..3010083
--- /dev/null
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestBufferedMutatorParams.java
@@ -0,0 +1,154 @@
+/*
+ *
+ * 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.hadoop.hbase.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.testclassification.ClientTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({ ClientTests.class, SmallTests.class })
+public class TestBufferedMutatorParams {
+
+ /**
+ * Just to create in instance, this doesn't actually function.
+ */
+ private class MockExecutorService implements ExecutorService {
+
+ public void execute(Runnable command) {
+ }
+
+ public void shutdown() {
+ }
+
+ public List<Runnable> shutdownNow() {
+ return null;
+ }
+
+ public boolean isShutdown() {
+ return false;
+ }
+
+ public boolean isTerminated() {
+ return false;
+ }
+
+ public boolean awaitTermination(long timeout, TimeUnit unit)
+ throws InterruptedException {
+ return false;
+ }
+
+ public <T> Future<T> submit(Callable<T> task) {
+ return null;
+ }
+
+ public <T> Future<T> submit(Runnable task, T result) {
+ return null;
+ }
+
+ public Future<?> submit(Runnable task) {
+ return null;
+ }
+
+ public <T> List<Future<T>> invokeAll(
+ Collection<? extends Callable<T>> tasks) throws InterruptedException {
+ return null;
+ }
+
+ public <T> List<Future<T>> invokeAll(
+ Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
+ throws InterruptedException {
+ return null;
+ }
+
+ public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
+ throws InterruptedException, ExecutionException {
+ return null;
+ }
+
+ public <T> T invokeAny(Collection<? extends Callable<T>> tasks,
+ long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException {
+ return null;
+ }
+ }
+
+ /**
+ * Just to create an instance, this doesn't actually function.
+ */
+ private class MockExceptionListener
+ implements BufferedMutator.ExceptionListener {
+ public void onException(RetriesExhaustedWithDetailsException exception,
+ BufferedMutator mutator) throws RetriesExhaustedWithDetailsException {
+ }
+ }
+
+ @Test
+ public void testClone() {
+ ExecutorService pool = new MockExecutorService();
+ BufferedMutatorParams bmp =
+ new BufferedMutatorParams(TableName.valueOf("SomeTableName"));
+
+ BufferedMutator.ExceptionListener listener = new MockExceptionListener();
+ bmp.writeBufferSize(17).maxKeyValueSize(13).pool(pool).listener(listener);
+ BufferedMutatorParams clone = bmp.clone();
+
+ // Confirm some literals
+ assertEquals("SomeTableName", clone.getTableName().toString());
+ assertEquals(17, clone.getWriteBufferSize());
+ assertEquals(13, clone.getMaxKeyValueSize());
+
+ cloneTest(bmp, clone);
+
+ BufferedMutatorParams cloneWars = clone.clone();
+ cloneTest(clone, cloneWars);
+ cloneTest(bmp, cloneWars);
+ }
+
+ /**
+ * Confirm all fields are equal.
+ * @param some some instance
+ * @param clone a clone of that instance, but not the same instance.
+ */
+ private void cloneTest(BufferedMutatorParams some,
+ BufferedMutatorParams clone) {
+ assertFalse(some == clone);
+ assertEquals(some.getTableName().toString(),
+ clone.getTableName().toString());
+ assertEquals(some.getWriteBufferSize(), clone.getWriteBufferSize());
+ assertEquals(some.getMaxKeyValueSize(), clone.getMaxKeyValueSize());
+ assertTrue(some.getListener() == clone.getListener());
+ assertTrue(some.getPool() == clone.getPool());
+ }
+
+}