use of org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator in project accumulo by apache.
the class ZooReaderWriterTest method testMutateNodeCreationFails.
@Test
public void testMutateNodeCreationFails() throws Exception {
final String path = "/foo";
final byte[] value = { 0 };
Mutator mutator = currentValue -> new byte[] { 1 };
zk.create(path, value, ZooUtil.PUBLIC, CreateMode.PERSISTENT);
expectLastCall().andThrow(new SessionExpiredException()).once();
expect(retry.canRetry()).andReturn(false);
expect(retry.retriesCompleted()).andReturn(1L).once();
replay(zk, zrw, retryFactory, retry);
assertThrows(SessionExpiredException.class, () -> zrw.mutateOrCreate(path, value, mutator));
}
use of org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator in project accumulo by apache.
the class ZooReaderWriterTest method testMutateWithBadVersion.
@Test
public void testMutateWithBadVersion() throws Exception {
final String path = "/foo";
final byte[] value = { 0 };
final byte[] mutatedBytes = { 1 };
Mutator mutator = currentValue -> mutatedBytes;
zrw = createMockBuilder(ZooReaderWriter.class).addMockedMethods("getRetryFactory", "getZooKeeper").createMock();
expect(zrw.getRetryFactory()).andReturn(retryFactory).anyTimes();
expect(zrw.getZooKeeper()).andReturn(zk).anyTimes();
Stat stat = new Stat();
zk.create(path, value, ZooUtil.PUBLIC, CreateMode.PERSISTENT);
expectLastCall().andThrow(new NodeExistsException()).once();
expect(zk.getData(path, null, stat)).andReturn(new byte[] { 3 }).times(2);
// BadVersionException should retry
expect(zk.setData(path, mutatedBytes, 0)).andThrow(new BadVersionException());
// Let 2nd setData succeed
expect(zk.setData(path, mutatedBytes, 0)).andReturn(null);
replay(zk, zrw, retryFactory, retry);
assertArrayEquals(new byte[] { 1 }, zrw.mutateOrCreate(path, value, mutator));
verify(zk, zrw, retryFactory, retry);
}
use of org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator in project accumulo by apache.
the class ZooReaderWriterTest method testMutateWithRetryOnSetData.
@Test
public void testMutateWithRetryOnSetData() throws Exception {
final String path = "/foo";
final byte[] value = { 0 };
final byte[] mutatedBytes = { 1 };
Mutator mutator = currentValue -> mutatedBytes;
zrw = createMockBuilder(ZooReaderWriter.class).addMockedMethods("getRetryFactory", "getZooKeeper").createMock();
expect(zrw.getRetryFactory()).andReturn(retryFactory).anyTimes();
expect(zrw.getZooKeeper()).andReturn(zk).anyTimes();
Stat stat = new Stat();
zk.create(path, value, ZooUtil.PUBLIC, CreateMode.PERSISTENT);
expectLastCall().andThrow(new NodeExistsException()).once();
expect(zk.getData(path, null, stat)).andReturn(new byte[] { 3 }).times(2);
// BadVersionException should retry
expect(zk.setData(path, mutatedBytes, 0)).andThrow(new ConnectionLossException());
expect(retry.canRetry()).andReturn(true);
retry.useRetry();
expectLastCall();
retry.waitForNextAttempt();
expectLastCall();
// Let 2nd setData succeed
expect(zk.setData(path, mutatedBytes, 0)).andReturn(null);
replay(zk, zrw, retryFactory, retry);
assertArrayEquals(new byte[] { 1 }, zrw.mutateOrCreate(path, value, mutator));
verify(zk, zrw, retryFactory, retry);
}
Aggregations