-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create DynamoDB tables on On-Demand billing mode by default. (#854)
* Create DynamoDB tables on On-Demand billing mode by default. This will enable KCL to create the DynamoDB tables - Lease and ShardProgress with the On-Demand billing mode instead of provisioned billing mode. * Keep previous table creation function for backward compatibility. * Added unit tests. * Added more unit tests.
- Loading branch information
Showing
11 changed files
with
294 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...t/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package software.amazon.kinesis.leases.dynamodb; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import software.amazon.kinesis.leases.LeaseRefresher; | ||
import software.amazon.kinesis.leases.exceptions.DependencyException; | ||
import software.amazon.kinesis.metrics.MetricsFactory; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class DynamoDBLeaseCoordinatorTest { | ||
|
||
private static final String WORKER_ID = UUID.randomUUID().toString(); | ||
private static final long LEASE_DURATION_MILLIS = 5000L; | ||
private static final long EPSILON_MILLIS = 25L; | ||
private static final int MAX_LEASES_FOR_WORKER = Integer.MAX_VALUE; | ||
private static final int MAX_LEASES_TO_STEAL_AT_ONE_TIME = 1; | ||
private static final int MAX_LEASE_RENEWER_THREAD_COUNT = 20; | ||
private static final long INITIAL_LEASE_TABLE_READ_CAPACITY = 10L; | ||
private static final long INITIAL_LEASE_TABLE_WRITE_CAPACITY = 10L; | ||
private static final long SECONDS_BETWEEN_POLLS = 10L; | ||
private static final long TIMEOUT_SECONDS = 600L; | ||
|
||
@Mock | ||
private LeaseRefresher leaseRefresher; | ||
@Mock | ||
private MetricsFactory metricsFactory; | ||
|
||
private DynamoDBLeaseCoordinator leaseCoordinator; | ||
|
||
@Before | ||
public void setup() { | ||
this.leaseCoordinator = new DynamoDBLeaseCoordinator(leaseRefresher, WORKER_ID, LEASE_DURATION_MILLIS, | ||
EPSILON_MILLIS, MAX_LEASES_FOR_WORKER, MAX_LEASES_TO_STEAL_AT_ONE_TIME, MAX_LEASE_RENEWER_THREAD_COUNT, | ||
INITIAL_LEASE_TABLE_READ_CAPACITY, INITIAL_LEASE_TABLE_WRITE_CAPACITY, metricsFactory); | ||
} | ||
|
||
@Test | ||
public void testInitialize_tableCreationSucceeds() throws Exception { | ||
when(leaseRefresher.createLeaseTableIfNotExists()).thenReturn(true); | ||
when(leaseRefresher.waitUntilLeaseTableExists(SECONDS_BETWEEN_POLLS, TIMEOUT_SECONDS)).thenReturn(true); | ||
|
||
leaseCoordinator.initialize(); | ||
|
||
verify(leaseRefresher, times(1)).createLeaseTableIfNotExists(); | ||
verify(leaseRefresher, times(1)).waitUntilLeaseTableExists(SECONDS_BETWEEN_POLLS, TIMEOUT_SECONDS); | ||
} | ||
|
||
@Test | ||
public void testInitialize_tableCreationFails() throws Exception { | ||
when(leaseRefresher.createLeaseTableIfNotExists()).thenReturn(false); | ||
when(leaseRefresher.waitUntilLeaseTableExists(SECONDS_BETWEEN_POLLS, TIMEOUT_SECONDS)).thenReturn(false); | ||
|
||
Assert.assertThrows(DependencyException.class, () -> leaseCoordinator.initialize()); | ||
verify(leaseRefresher, times(1)).createLeaseTableIfNotExists(); | ||
verify(leaseRefresher, times(1)).waitUntilLeaseTableExists(SECONDS_BETWEEN_POLLS, TIMEOUT_SECONDS); | ||
} | ||
} |
Oops, something went wrong.