Search in sources :

Example 1 with KinesisClientLease

use of com.amazonaws.services.kinesis.leases.impl.KinesisClientLease in project carbonj by salesforce.

the class TestMemLeaseManager method testBasicPath.

@Test
public void testBasicPath() throws Exception {
    ILeaseManager<KinesisClientLease> leaseManager = new MemLeaseManager<>(1);
    // check if the lease table exists
    Assert.assertFalse(leaseManager.leaseTableExists());
    // create table if it not exists
    Assert.assertTrue(leaseManager.createLeaseTableIfNotExists(10L, 10L));
    // check if the lease table exists
    Assert.assertTrue(leaseManager.waitUntilLeaseTableExists(1, 10));
    // check if the lease table exists
    Assert.assertTrue(leaseManager.leaseTableExists());
    // check if the lease table is empty
    Assert.assertTrue(leaseManager.isLeaseTableEmpty());
    Assert.assertEquals(0, leaseManager.listLeases().size());
    // create lease for 5 shards
    for (int i = 0; i < NO_OF_SHARDS; i++) {
        String shardId = "shard-" + i;
        KinesisClientLease lease = newKCLLease(shardId);
        Assert.assertTrue(leaseManager.createLeaseIfNotExists(lease));
    }
    // check if the lease table is not empty
    Assert.assertFalse(leaseManager.isLeaseTableEmpty());
    Assert.assertEquals(5, leaseManager.listLeases().size());
    verify(leaseManager, null, 0L);
    for (int i = 0; i < NO_OF_SHARDS; i++) {
        String shardId = "shard-" + i;
        KinesisClientLease lease = leaseManager.getLease(shardId);
        leaseManager.takeLease(lease, OWNER);
    }
    verify(leaseManager, OWNER, 1L);
    renewLeases(leaseManager);
    verify(leaseManager, OWNER, 2L);
    updateLeases(leaseManager);
    verify(leaseManager, OWNER, 3L);
}
Also used : MemLeaseManager(com.demandware.carbonj.service.engine.kinesis.kcl.MemLeaseManager) KinesisClientLease(com.amazonaws.services.kinesis.leases.impl.KinesisClientLease) Test(org.junit.Test)

Example 2 with KinesisClientLease

use of com.amazonaws.services.kinesis.leases.impl.KinesisClientLease in project carbonj by salesforce.

the class TestMemLeaseManager method verify.

private void verify(ILeaseManager<KinesisClientLease> leaseManager, String expectedOwner, Long expectedLeaseCounter) throws Exception {
    for (int i = 0; i < NO_OF_SHARDS; i++) {
        String shardId = "shard-" + i;
        KinesisClientLease lease = leaseManager.getLease(shardId);
        Assert.assertEquals(expectedOwner, lease.getLeaseOwner());
        Assert.assertEquals(expectedLeaseCounter, lease.getLeaseCounter());
    }
    Assert.assertEquals(NO_OF_SHARDS, leaseManager.listLeases().size());
}
Also used : KinesisClientLease(com.amazonaws.services.kinesis.leases.impl.KinesisClientLease)

Example 3 with KinesisClientLease

use of com.amazonaws.services.kinesis.leases.impl.KinesisClientLease in project carbonj by salesforce.

the class TestMemLeaseManager method updateLeases.

private void updateLeases(ILeaseManager<KinesisClientLease> leaseManager) throws Exception {
    for (int i = 0; i < NO_OF_SHARDS; i++) {
        String shardId = "shard-" + i;
        KinesisClientLease lease = leaseManager.getLease(shardId);
        leaseManager.updateLease(lease);
    }
}
Also used : KinesisClientLease(com.amazonaws.services.kinesis.leases.impl.KinesisClientLease)

Example 4 with KinesisClientLease

use of com.amazonaws.services.kinesis.leases.impl.KinesisClientLease in project carbonj by salesforce.

the class TestMemLeaseManager method renewLeases.

private void renewLeases(ILeaseManager<KinesisClientLease> leaseManager) throws Exception {
    for (int i = 0; i < NO_OF_SHARDS; i++) {
        String shardId = "shard-" + i;
        KinesisClientLease lease = leaseManager.getLease(shardId);
        leaseManager.renewLease(lease);
    }
}
Also used : KinesisClientLease(com.amazonaws.services.kinesis.leases.impl.KinesisClientLease)

Example 5 with KinesisClientLease

use of com.amazonaws.services.kinesis.leases.impl.KinesisClientLease in project carbonj by salesforce.

the class TestMemLeaseManager method newKCLLease.

private static KinesisClientLease newKCLLease(String shardId) {
    KinesisClientLease newLease = new KinesisClientLease();
    newLease.setLeaseKey(shardId);
    List<String> parentShardIds = new ArrayList<>();
    newLease.setParentShardIds(parentShardIds);
    newLease.setOwnerSwitchesSinceCheckpoint(0L);
    return newLease;
}
Also used : KinesisClientLease(com.amazonaws.services.kinesis.leases.impl.KinesisClientLease) ArrayList(java.util.ArrayList)

Aggregations

KinesisClientLease (com.amazonaws.services.kinesis.leases.impl.KinesisClientLease)5 MemLeaseManager (com.demandware.carbonj.service.engine.kinesis.kcl.MemLeaseManager)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1