Search in sources :

Example 1 with RetryFactory

use of org.apache.accumulo.fate.util.Retry.RetryFactory 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));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RetryFactory(org.apache.accumulo.fate.util.Retry.RetryFactory) CreateMode(org.apache.zookeeper.CreateMode) BadVersionException(org.apache.zookeeper.KeeperException.BadVersionException) ZooKeeper(org.apache.zookeeper.ZooKeeper) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) BeforeEach(org.junit.jupiter.api.BeforeEach) EasyMock.createMockBuilder(org.easymock.EasyMock.createMockBuilder) Retry(org.apache.accumulo.fate.util.Retry) KeeperException(org.apache.zookeeper.KeeperException) Mutator(org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator) EasyMock.expect(org.easymock.EasyMock.expect) Stat(org.apache.zookeeper.data.Stat) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Test(org.junit.jupiter.api.Test) EasyMock.replay(org.easymock.EasyMock.replay) EasyMock.createMock(org.easymock.EasyMock.createMock) EasyMock.verify(org.easymock.EasyMock.verify) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) Code(org.apache.zookeeper.KeeperException.Code) Mutator(org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) Test(org.junit.jupiter.api.Test)

Example 2 with RetryFactory

use of org.apache.accumulo.fate.util.Retry.RetryFactory 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);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RetryFactory(org.apache.accumulo.fate.util.Retry.RetryFactory) CreateMode(org.apache.zookeeper.CreateMode) BadVersionException(org.apache.zookeeper.KeeperException.BadVersionException) ZooKeeper(org.apache.zookeeper.ZooKeeper) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) BeforeEach(org.junit.jupiter.api.BeforeEach) EasyMock.createMockBuilder(org.easymock.EasyMock.createMockBuilder) Retry(org.apache.accumulo.fate.util.Retry) KeeperException(org.apache.zookeeper.KeeperException) Mutator(org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator) EasyMock.expect(org.easymock.EasyMock.expect) Stat(org.apache.zookeeper.data.Stat) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Test(org.junit.jupiter.api.Test) EasyMock.replay(org.easymock.EasyMock.replay) EasyMock.createMock(org.easymock.EasyMock.createMock) EasyMock.verify(org.easymock.EasyMock.verify) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) Code(org.apache.zookeeper.KeeperException.Code) Stat(org.apache.zookeeper.data.Stat) Mutator(org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) BadVersionException(org.apache.zookeeper.KeeperException.BadVersionException) Test(org.junit.jupiter.api.Test)

Example 3 with RetryFactory

use of org.apache.accumulo.fate.util.Retry.RetryFactory in project accumulo by apache.

the class RetryTest method properArgumentsInUnlimitedRetry.

@Test
public void properArgumentsInUnlimitedRetry() {
    long startWait = 50L, maxWait = 5000L, waitIncrement = 500L, logInterval = 10000L;
    double waitFactor = 1.0;
    RetryFactory factory = Retry.builder().infiniteRetries().retryAfter(startWait, MS).incrementBy(waitIncrement, MS).maxWait(maxWait, MS).backOffFactor(waitFactor).logInterval(logInterval, MS).createFactory();
    Retry retry = factory.createRetry();
    assertEquals(-1, retry.getMaxRetries());
    assertEquals(startWait, retry.getCurrentWait());
    assertEquals(maxWait, retry.getMaxWait());
    assertEquals(waitIncrement, retry.getWaitIncrement());
    assertEquals(logInterval, retry.getLogInterval());
}
Also used : RetryFactory(org.apache.accumulo.fate.util.Retry.RetryFactory) Test(org.junit.jupiter.api.Test)

Example 4 with RetryFactory

use of org.apache.accumulo.fate.util.Retry.RetryFactory 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);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RetryFactory(org.apache.accumulo.fate.util.Retry.RetryFactory) CreateMode(org.apache.zookeeper.CreateMode) BadVersionException(org.apache.zookeeper.KeeperException.BadVersionException) ZooKeeper(org.apache.zookeeper.ZooKeeper) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) BeforeEach(org.junit.jupiter.api.BeforeEach) EasyMock.createMockBuilder(org.easymock.EasyMock.createMockBuilder) Retry(org.apache.accumulo.fate.util.Retry) KeeperException(org.apache.zookeeper.KeeperException) Mutator(org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator) EasyMock.expect(org.easymock.EasyMock.expect) Stat(org.apache.zookeeper.data.Stat) SessionExpiredException(org.apache.zookeeper.KeeperException.SessionExpiredException) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Test(org.junit.jupiter.api.Test) EasyMock.replay(org.easymock.EasyMock.replay) EasyMock.createMock(org.easymock.EasyMock.createMock) EasyMock.verify(org.easymock.EasyMock.verify) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) Code(org.apache.zookeeper.KeeperException.Code) Stat(org.apache.zookeeper.data.Stat) Mutator(org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) Test(org.junit.jupiter.api.Test)

Example 5 with RetryFactory

use of org.apache.accumulo.fate.util.Retry.RetryFactory in project accumulo by apache.

the class RetryTest method properArgumentsInRetry.

@Test
public void properArgumentsInRetry() {
    long maxRetries = 10, startWait = 50L, maxWait = 5000L, waitIncrement = 500L, logInterval = 10000L;
    RetryFactory factory = Retry.builder().maxRetries(maxRetries).retryAfter(startWait, MS).incrementBy(waitIncrement, MS).maxWait(maxWait, MS).backOffFactor(1).logInterval(logInterval, MS).createFactory();
    Retry retry = factory.createRetry();
    assertEquals(maxRetries, retry.getMaxRetries());
    assertEquals(startWait, retry.getCurrentWait());
    assertEquals(maxWait, retry.getMaxWait());
    assertEquals(waitIncrement, retry.getWaitIncrement());
    assertEquals(logInterval, retry.getLogInterval());
}
Also used : RetryFactory(org.apache.accumulo.fate.util.Retry.RetryFactory) Test(org.junit.jupiter.api.Test)

Aggregations

RetryFactory (org.apache.accumulo.fate.util.Retry.RetryFactory)5 Test (org.junit.jupiter.api.Test)5 Retry (org.apache.accumulo.fate.util.Retry)3 Mutator (org.apache.accumulo.fate.zookeeper.ZooReaderWriter.Mutator)3 CreateMode (org.apache.zookeeper.CreateMode)3 KeeperException (org.apache.zookeeper.KeeperException)3 BadVersionException (org.apache.zookeeper.KeeperException.BadVersionException)3 Code (org.apache.zookeeper.KeeperException.Code)3 ConnectionLossException (org.apache.zookeeper.KeeperException.ConnectionLossException)3 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)3 SessionExpiredException (org.apache.zookeeper.KeeperException.SessionExpiredException)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 Stat (org.apache.zookeeper.data.Stat)3 EasyMock.createMock (org.easymock.EasyMock.createMock)3 EasyMock.createMockBuilder (org.easymock.EasyMock.createMockBuilder)3 EasyMock.expect (org.easymock.EasyMock.expect)3 EasyMock.expectLastCall (org.easymock.EasyMock.expectLastCall)3 EasyMock.replay (org.easymock.EasyMock.replay)3 EasyMock.verify (org.easymock.EasyMock.verify)3 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)3