Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3E8D317347 for ; Fri, 1 May 2015 15:27:57 +0000 (UTC) Received: (qmail 23043 invoked by uid 500); 1 May 2015 15:27:49 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 22969 invoked by uid 500); 1 May 2015 15:27:49 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 21195 invoked by uid 99); 1 May 2015 15:27:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 May 2015 15:27:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id ED103E2F1B; Fri, 1 May 2015 15:27:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jmhsieh@apache.org To: commits@hbase.apache.org Date: Fri, 01 May 2015 15:28:17 -0000 Message-Id: <3f9891567a6541b0b2b5534edcb8d8bb@git.apache.org> In-Reply-To: <796e851ddf624447b659d7459be1f3c1@git.apache.org> References: <796e851ddf624447b659d7459be1f3c1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [31/50] [abbrv] hbase git commit: HBASE-13457 SnapshotExistsException doesn't honor the DoNotRetry HBASE-13457 SnapshotExistsException doesn't honor the DoNotRetry Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/e9da064c Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/e9da064c Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/e9da064c Branch: refs/heads/hbase-11339 Commit: e9da064ccd8dd3c64d99e0863e36cdc1236779f1 Parents: 679e0e8 Author: Matteo Bertozzi Authored: Mon Apr 13 23:21:50 2015 +0100 Committer: Matteo Bertozzi Committed: Mon Apr 13 23:21:50 2015 +0100 ---------------------------------------------------------------------- .../hbase/snapshot/SnapshotExistsException.java | 3 + .../snapshot/TestSnapshotClientRetries.java | 125 +++++++++++++++++++ 2 files changed, 128 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/e9da064c/hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotExistsException.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotExistsException.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotExistsException.java index 2c609d9..172c89e 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotExistsException.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotExistsException.java @@ -28,6 +28,9 @@ import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescriptio @InterfaceAudience.Public @InterfaceStability.Evolving public class SnapshotExistsException extends HBaseSnapshotException { + public SnapshotExistsException(String msg) { + super(msg); + } /** * Failure due to the snapshot already existing http://git-wip-us.apache.org/repos/asf/hbase/blob/e9da064c/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java new file mode 100644 index 0000000..5168b85 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java @@ -0,0 +1,125 @@ +/** + * + * 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.snapshot; + +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.coprocessor.BaseMasterObserver; +import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; +import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; +import org.apache.hadoop.hbase.coprocessor.ObserverContext; +import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; +import org.apache.hadoop.hbase.snapshot.SnapshotExistsException; +import org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.util.TestTableName; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@Category({ MediumTests.class }) +public class TestSnapshotClientRetries { + private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + private static final Log LOG = LogFactory.getLog(TestSnapshotClientRetries.class); + + @Rule public TestTableName TEST_TABLE = new TestTableName(); + + @Before + public void setUp() throws Exception { + TEST_UTIL.getConfiguration().set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, + MasterSyncObserver.class.getName()); + TEST_UTIL.startMiniCluster(1); + } + + @After + public void tearDown() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + @Test(timeout = 60000, expected=SnapshotExistsException.class) + public void testSnapshotAlreadyExist() throws Exception { + final String snapshotName = "testSnapshotAlreadyExist"; + TEST_UTIL.createTable(TEST_TABLE.getTableName(), "f"); + TEST_UTIL.getHBaseAdmin().snapshot(snapshotName, TEST_TABLE.getTableName()); + snapshotAndAssertOneRetry(snapshotName, TEST_TABLE.getTableName()); + } + + @Test(timeout = 60000, expected=SnapshotDoesNotExistException.class) + public void testCloneNonExistentSnapshot() throws Exception { + final String snapshotName = "testCloneNonExistentSnapshot"; + cloneAndAssertOneRetry(snapshotName, TEST_TABLE.getTableName()); + } + + public static class MasterSyncObserver extends BaseMasterObserver { + volatile AtomicInteger snapshotCount = null; + volatile AtomicInteger cloneCount = null; + + @Override + public void preSnapshot(final ObserverContext ctx, + final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor) + throws IOException { + if (snapshotCount != null) { + snapshotCount.incrementAndGet(); + } + } + + @Override + public void preCloneSnapshot(final ObserverContext ctx, + final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor) + throws IOException { + if (cloneCount != null) { + cloneCount.incrementAndGet(); + } + } + } + + public void snapshotAndAssertOneRetry(final String snapshotName, final TableName tableName) + throws Exception { + MasterSyncObserver observer = getMasterSyncObserver(); + observer.snapshotCount = new AtomicInteger(0); + TEST_UTIL.getHBaseAdmin().snapshot(snapshotName, tableName); + assertEquals(1, observer.snapshotCount.get()); + } + + public void cloneAndAssertOneRetry(final String snapshotName, final TableName tableName) + throws Exception { + MasterSyncObserver observer = getMasterSyncObserver(); + observer.cloneCount = new AtomicInteger(0); + TEST_UTIL.getHBaseAdmin().cloneSnapshot(snapshotName, tableName); + assertEquals(1, observer.cloneCount.get()); + } + + private MasterSyncObserver getMasterSyncObserver() { + return (MasterSyncObserver)TEST_UTIL.getHBaseCluster().getMaster() + .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class.getName()); + } +}