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);
}
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);
}
Aggregations