Search in sources :

Example 1 with ScheduledTaskCapturingEventLoop

use of com.datastax.oss.driver.internal.core.util.concurrent.ScheduledTaskCapturingEventLoop in project java-driver by datastax.

the class DefaultDriverConfigLoaderTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    when(context.getSessionName()).thenReturn("test");
    when(context.getNettyOptions()).thenReturn(nettyOptions);
    when(nettyOptions.adminEventExecutorGroup()).thenReturn(adminEventExecutorGroup);
    adminExecutor = new ScheduledTaskCapturingEventLoop(adminEventExecutorGroup);
    when(adminEventExecutorGroup.next()).thenReturn(adminExecutor);
    eventBus = spy(new EventBus("test"));
    when(context.getEventBus()).thenReturn(eventBus);
    // The already loaded config in the context.
    // In real life, it's the object managed by the loader, but in this test it's simpler to mock
    // it.
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(defaultProfile);
    when(defaultProfile.getDuration(DefaultDriverOption.CONFIG_RELOAD_INTERVAL)).thenReturn(Duration.ofSeconds(12));
    configSource = new AtomicReference<>("int1 = 42");
}
Also used : EventBus(com.datastax.oss.driver.internal.core.context.EventBus) ScheduledTaskCapturingEventLoop(com.datastax.oss.driver.internal.core.util.concurrent.ScheduledTaskCapturingEventLoop) Before(org.junit.Before)

Example 2 with ScheduledTaskCapturingEventLoop

use of com.datastax.oss.driver.internal.core.util.concurrent.ScheduledTaskCapturingEventLoop in project java-driver by datastax.

the class RateLimitingRequestThrottlerTest method setup.

@Before
public void setup() {
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(defaultProfile);
    when(defaultProfile.getInt(DefaultDriverOption.REQUEST_THROTTLER_MAX_REQUESTS_PER_SECOND)).thenReturn(5);
    when(defaultProfile.getInt(DefaultDriverOption.REQUEST_THROTTLER_MAX_QUEUE_SIZE)).thenReturn(10);
    // Set to match the time to reissue one permit. Although it does not matter in practice, since
    // the executor is mocked and we trigger tasks manually.
    when(defaultProfile.getDuration(DefaultDriverOption.REQUEST_THROTTLER_DRAIN_INTERVAL)).thenReturn(DRAIN_INTERVAL);
    when(context.getNettyOptions()).thenReturn(nettyOptions);
    when(nettyOptions.adminEventExecutorGroup()).thenReturn(adminGroup);
    adminExecutor = new ScheduledTaskCapturingEventLoop(adminGroup);
    when(adminGroup.next()).thenReturn(adminExecutor);
    throttler = new RateLimitingRequestThrottler(context, clock);
}
Also used : ScheduledTaskCapturingEventLoop(com.datastax.oss.driver.internal.core.util.concurrent.ScheduledTaskCapturingEventLoop) Before(org.junit.Before)

Aggregations

ScheduledTaskCapturingEventLoop (com.datastax.oss.driver.internal.core.util.concurrent.ScheduledTaskCapturingEventLoop)2 Before (org.junit.Before)2 EventBus (com.datastax.oss.driver.internal.core.context.EventBus)1