Added unit tests for ILeaseManager injection in Worker Builder
This commit is contained in:
parent
1f7a05eb02
commit
e190105e35
2 changed files with 34 additions and 0 deletions
|
|
@ -426,6 +426,13 @@ public class Worker implements Runnable {
|
|||
return applicationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the leaseCoordinator
|
||||
*/
|
||||
KinesisClientLibLeaseCoordinator getLeaseCoordinator(){
|
||||
return leaseCoordinator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start consuming data from the stream, and pass it to the application record processors.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1500,6 +1500,33 @@ public class WorkerTest {
|
|||
Assert.assertTrue(worker.getStreamConfig().getStreamProxy() instanceof KinesisLocalFileProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilderWithDefaultLeaseManager() {
|
||||
IRecordProcessorFactory recordProcessorFactory = mock(IRecordProcessorFactory.class);
|
||||
|
||||
Worker worker = new Worker.Builder()
|
||||
.recordProcessorFactory(recordProcessorFactory)
|
||||
.config(config)
|
||||
.build();
|
||||
|
||||
Assert.assertNotNull(worker.getLeaseCoordinator().getLeaseManager());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testBuilderWhenLeaseManagerIsSet() {
|
||||
IRecordProcessorFactory recordProcessorFactory = mock(IRecordProcessorFactory.class);
|
||||
// Create an instance of ILeaseManager for injection and validation
|
||||
ILeaseManager<KinesisClientLease> leaseManager = (ILeaseManager<KinesisClientLease>) mock(ILeaseManager.class);
|
||||
Worker worker = new Worker.Builder()
|
||||
.recordProcessorFactory(recordProcessorFactory)
|
||||
.config(config)
|
||||
.leaseManager(leaseManager)
|
||||
.build();
|
||||
|
||||
Assert.assertSame(leaseManager, worker.getLeaseCoordinator().getLeaseManager());
|
||||
}
|
||||
|
||||
private abstract class InjectableWorker extends Worker {
|
||||
InjectableWorker(String applicationName, IRecordProcessorFactory recordProcessorFactory,
|
||||
KinesisClientLibConfiguration config, StreamConfig streamConfig,
|
||||
|
|
|
|||
Loading…
Reference in a new issue