Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-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 D91FE1839C for ; Wed, 27 May 2015 20:47:29 +0000 (UTC) Received: (qmail 25654 invoked by uid 500); 27 May 2015 20:47:29 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 25559 invoked by uid 500); 27 May 2015 20:47:29 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 25226 invoked by uid 99); 27 May 2015 20:47:29 -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; Wed, 27 May 2015 20:47:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7715AE00DC; Wed, 27 May 2015 20:47:29 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: elserj@apache.org To: commits@accumulo.apache.org Date: Wed, 27 May 2015 20:47:36 -0000 Message-Id: <5d9f34409ac14ba2b5f8491096dceabf@git.apache.org> In-Reply-To: <0746f4e8b05c48a4b91d8e401b6b83cf@git.apache.org> References: <0746f4e8b05c48a4b91d8e401b6b83cf@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [08/17] accumulo git commit: Merge branch '1.6' into 1.7 Merge branch '1.6' into 1.7 Conflicts: proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/6dab32ed Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/6dab32ed Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/6dab32ed Branch: refs/heads/master Commit: 6dab32ed2c2f5c901592d216a170578df5a3f2a4 Parents: caef59e c9f33d0 Author: Josh Elser Authored: Wed May 27 16:45:46 2015 -0400 Committer: Josh Elser Committed: Wed May 27 16:45:46 2015 -0400 ---------------------------------------------------------------------- proxy/pom.xml | 5 + .../org/apache/accumulo/proxy/ProxyServer.java | 16 ++- .../apache/accumulo/proxy/ProxyServerTest.java | 114 +++++++++++++++++++ 3 files changed, 131 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/6dab32ed/proxy/pom.xml ---------------------------------------------------------------------- diff --cc proxy/pom.xml index 5da2763,ee106c7..1b3f122 --- a/proxy/pom.xml +++ b/proxy/pom.xml @@@ -82,6 -77,11 +82,11 @@@ test - org.apache.accumulo - accumulo-test ++ org.easymock ++ easymock + test + + org.slf4j slf4j-log4j12 test http://git-wip-us.apache.org/repos/asf/accumulo/blob/6dab32ed/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java ---------------------------------------------------------------------- diff --cc proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java index e2dabe5,abd225c..88dad8d --- a/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java +++ b/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java @@@ -1182,8 -1139,9 +1182,9 @@@ public class ProxyServer implements Acc public void updateAndFlush(ByteBuffer login, String tableName, Map> cells) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, org.apache.accumulo.proxy.thrift.MutationsRejectedException, TException { - BatchWriterPlusException bwpe = null; ++ BatchWriterPlusProblem bwpe = null; try { - BatchWriterPlusProblem bwpe = getWriter(login, tableName, null); + bwpe = getWriter(login, tableName, null); addCellsToWriter(cells, bwpe); if (bwpe.exception != null) throw bwpe.exception; @@@ -1196,7 -1161,7 +1204,7 @@@ private static final ColumnVisibility EMPTY_VIS = new ColumnVisibility(); - private void addCellsToWriter(Map> cells, BatchWriterPlusProblem bwpe) { - void addCellsToWriter(Map> cells, BatchWriterPlusException bwpe) { ++ void addCellsToWriter(Map> cells, BatchWriterPlusProblem bwpe) { if (bwpe.exception != null) return; @@@ -1320,7 -1285,7 +1328,7 @@@ return bwpe; } - private BatchWriterPlusProblem getWriter(ByteBuffer login, String tableName, WriterOptions opts) throws Exception { - BatchWriterPlusException getWriter(ByteBuffer login, String tableName, WriterOptions opts) throws Exception { ++ BatchWriterPlusProblem getWriter(ByteBuffer login, String tableName, WriterOptions opts) throws Exception { BatchWriterConfig cfg = new BatchWriterConfig(); if (opts != null) { if (opts.maxMemory != 0) http://git-wip-us.apache.org/repos/asf/accumulo/blob/6dab32ed/proxy/src/test/java/org/apache/accumulo/proxy/ProxyServerTest.java ---------------------------------------------------------------------- diff --cc proxy/src/test/java/org/apache/accumulo/proxy/ProxyServerTest.java index 0000000,ed4f313..24201e7 mode 000000,100644..100644 --- a/proxy/src/test/java/org/apache/accumulo/proxy/ProxyServerTest.java +++ b/proxy/src/test/java/org/apache/accumulo/proxy/ProxyServerTest.java @@@ -1,0 -1,114 +1,114 @@@ + /* + * 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.accumulo.proxy; + + import java.nio.ByteBuffer; + import java.nio.charset.Charset; + import java.util.HashMap; + import java.util.List; + import java.util.Map; + + import org.apache.accumulo.core.client.BatchWriter; + import org.apache.accumulo.core.client.MutationsRejectedException; -import org.apache.accumulo.proxy.ProxyServer.BatchWriterPlusException; ++import org.apache.accumulo.proxy.ProxyServer.BatchWriterPlusProblem; + import org.apache.accumulo.proxy.thrift.ColumnUpdate; + import org.apache.accumulo.proxy.thrift.WriterOptions; + import org.easymock.EasyMock; + import org.junit.Assert; + import org.junit.Test; + + /** + * + */ + public class ProxyServerTest { + + private static final Charset UTF_8 = Charset.forName("UTF-8"); + + @Test + public void updateAndFlushClosesWriterOnExceptionFromAddCells() throws Exception { + ProxyServer server = EasyMock.createMockBuilder(ProxyServer.class).addMockedMethod("getWriter", ByteBuffer.class, String.class, WriterOptions.class) - .addMockedMethod("addCellsToWriter", Map.class, BatchWriterPlusException.class).createMock(); ++ .addMockedMethod("addCellsToWriter", Map.class, BatchWriterPlusProblem.class).createMock(); + BatchWriter writer = EasyMock.createMock(BatchWriter.class); - BatchWriterPlusException bwpe = new BatchWriterPlusException(); ++ BatchWriterPlusProblem bwpe = new BatchWriterPlusProblem(); + bwpe.writer = writer; + MutationsRejectedException mre = EasyMock.createMock(MutationsRejectedException.class); + + final ByteBuffer login = ByteBuffer.wrap("my_login".getBytes(UTF_8)); - final String tableName = "table1"; ++ final String tableName = "table1"; + final Map> cells = new HashMap>(); + + EasyMock.expect(server.getWriter(login, tableName, null)).andReturn(bwpe); + server.addCellsToWriter(cells, bwpe); + EasyMock.expectLastCall(); + + // Set the exception + bwpe.exception = mre; + + writer.close(); + EasyMock.expectLastCall(); + + EasyMock.replay(server, writer, mre); + + try { + server.updateAndFlush(login, tableName, cells); + Assert.fail("Expected updateAndFlush to throw an exception"); + } catch (org.apache.accumulo.proxy.thrift.MutationsRejectedException e) { + // pass + } + + EasyMock.verify(server, writer, mre); + } + + @Test + public void updateAndFlushClosesWriterOnExceptionFromFlush() throws Exception { + ProxyServer server = EasyMock.createMockBuilder(ProxyServer.class).addMockedMethod("getWriter", ByteBuffer.class, String.class, WriterOptions.class) - .addMockedMethod("addCellsToWriter", Map.class, BatchWriterPlusException.class).createMock(); ++ .addMockedMethod("addCellsToWriter", Map.class, BatchWriterPlusProblem.class).createMock(); + BatchWriter writer = EasyMock.createMock(BatchWriter.class); - BatchWriterPlusException bwpe = new BatchWriterPlusException(); ++ BatchWriterPlusProblem bwpe = new BatchWriterPlusProblem(); + bwpe.writer = writer; + MutationsRejectedException mre = EasyMock.createMock(MutationsRejectedException.class); + + final ByteBuffer login = ByteBuffer.wrap("my_login".getBytes(UTF_8)); - final String tableName = "table1"; ++ final String tableName = "table1"; + final Map> cells = new HashMap>(); + + EasyMock.expect(server.getWriter(login, tableName, null)).andReturn(bwpe); + server.addCellsToWriter(cells, bwpe); + EasyMock.expectLastCall(); + + // No exception throw adding the cells + bwpe.exception = null; + + writer.flush(); + EasyMock.expectLastCall().andThrow(mre); + + writer.close(); + EasyMock.expectLastCall(); + + EasyMock.replay(server, writer, mre); + + try { + server.updateAndFlush(login, tableName, cells); + Assert.fail("Expected updateAndFlush to throw an exception"); + } catch (org.apache.accumulo.proxy.thrift.MutationsRejectedException e) { + // pass + } + + EasyMock.verify(server, writer, mre); + } - ++ + }