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/1.7 Commit: 6dab32ed2c2f5c901592d216a170578df5a3f2a4 Parents: caef59e c9f33d0 Author: Josh Elser <els...@apache.org> Authored: Wed May 27 16:45:46 2015 -0400 Committer: Josh Elser <els...@apache.org> 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 @@@ <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.accumulo</groupId> - <artifactId>accumulo-test</artifactId> ++ <groupId>org.easymock</groupId> ++ <artifactId>easymock</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <scope>test</scope> 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<ByteBuffer,List<ColumnUpdate>> 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<ByteBuffer,List<ColumnUpdate>> cells, BatchWriterPlusProblem bwpe) { - void addCellsToWriter(Map<ByteBuffer,List<ColumnUpdate>> cells, BatchWriterPlusException bwpe) { ++ void addCellsToWriter(Map<ByteBuffer,List<ColumnUpdate>> 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<ByteBuffer,List<ColumnUpdate>> cells = new HashMap<ByteBuffer,List<ColumnUpdate>>(); + + 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<ByteBuffer,List<ColumnUpdate>> cells = new HashMap<ByteBuffer,List<ColumnUpdate>>(); + + 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); + } - ++ + }