Search in sources :

Example 1 with BatchWriterPlusProblem

use of org.apache.accumulo.proxy.ProxyServer.BatchWriterPlusProblem in project accumulo by apache.

the class ProxyServerTest method updateAndFlushClosesWriterOnExceptionFromFlush.

@Test
public void updateAndFlushClosesWriterOnExceptionFromFlush() throws Exception {
    ProxyServer server = EasyMock.createMockBuilder(ProxyServer.class).addMockedMethod("getWriter", ByteBuffer.class, String.class, WriterOptions.class).addMockedMethod("addCellsToWriter", Map.class, BatchWriterPlusProblem.class).createMock();
    BatchWriter writer = EasyMock.createMock(BatchWriter.class);
    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 Map<ByteBuffer, List<ColumnUpdate>> 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);
}
Also used : HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) BatchWriterPlusProblem(org.apache.accumulo.proxy.ProxyServer.BatchWriterPlusProblem) List(java.util.List) BatchWriter(org.apache.accumulo.core.client.BatchWriter) HashMap(java.util.HashMap) Map(java.util.Map) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) Test(org.junit.Test)

Example 2 with BatchWriterPlusProblem

use of org.apache.accumulo.proxy.ProxyServer.BatchWriterPlusProblem in project accumulo by apache.

the class ProxyServerTest method updateAndFlushClosesWriterOnExceptionFromAddCells.

@Test
public void updateAndFlushClosesWriterOnExceptionFromAddCells() throws Exception {
    ProxyServer server = EasyMock.createMockBuilder(ProxyServer.class).addMockedMethod("getWriter", ByteBuffer.class, String.class, WriterOptions.class).addMockedMethod("addCellsToWriter", Map.class, BatchWriterPlusProblem.class).createMock();
    BatchWriter writer = EasyMock.createMock(BatchWriter.class);
    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 Map<ByteBuffer, List<ColumnUpdate>> 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);
}
Also used : HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) BatchWriterPlusProblem(org.apache.accumulo.proxy.ProxyServer.BatchWriterPlusProblem) List(java.util.List) BatchWriter(org.apache.accumulo.core.client.BatchWriter) HashMap(java.util.HashMap) Map(java.util.Map) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 BatchWriter (org.apache.accumulo.core.client.BatchWriter)2 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)2 BatchWriterPlusProblem (org.apache.accumulo.proxy.ProxyServer.BatchWriterPlusProblem)2 Test (org.junit.Test)2