use of com.datastax.oss.driver.internal.core.context.EventBus in project java-driver by datastax.
the class MetricsITBase method should_not_evict_down_node_metrics_when_node_is_back_up_before_timeout.
@Test
public void should_not_evict_down_node_metrics_when_node_is_back_up_before_timeout() throws Exception {
// given
Duration expireAfter = Duration.ofSeconds(2);
DriverConfigLoader loader = allMetricsEnabled().withDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER, expireAfter).build();
AbstractMetricUpdater.MIN_EXPIRE_AFTER = expireAfter;
try (CqlSession session = CqlSession.builder().addContactEndPoints(simulacron().getContactPoints()).withConfigLoader(loader).withMetricRegistry(newMetricRegistry()).build()) {
queryAllNodes(session);
DefaultNode node1 = findNode(session, 0);
DefaultNode node2 = findNode(session, 1);
DefaultNode node3 = findNode(session, 2);
EventBus eventBus = ((InternalDriverContext) session.getContext()).getEventBus();
// trigger nodes UP -> DOWN
eventBus.fire(NodeStateEvent.changed(NodeState.UP, NodeState.DOWN, node1));
eventBus.fire(NodeStateEvent.changed(NodeState.UP, NodeState.FORCED_DOWN, node2));
eventBus.fire(NodeStateEvent.removed(node3));
Thread.sleep(500);
// trigger nodes DOWN -> UP, should cancel the timeouts
eventBus.fire(NodeStateEvent.changed(NodeState.DOWN, NodeState.UP, node1));
eventBus.fire(NodeStateEvent.changed(NodeState.FORCED_DOWN, NodeState.UP, node2));
eventBus.fire(NodeStateEvent.added(node3));
Thread.sleep(expireAfter.toMillis());
// then no node-level metrics should be evicted
assertNodeMetricsNotEvicted(session, node1);
assertNodeMetricsNotEvicted(session, node2);
assertNodeMetricsNotEvicted(session, node3);
} finally {
AbstractMetricUpdater.MIN_EXPIRE_AFTER = Duration.ofMinutes(5);
}
}
use of com.datastax.oss.driver.internal.core.context.EventBus in project java-driver by datastax.
the class DefaultSessionPoolsTest method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
DefaultEventLoopGroup adminEventLoopGroup = new DefaultEventLoopGroup(1);
when(nettyOptions.adminEventExecutorGroup()).thenReturn(adminEventLoopGroup);
when(context.getNettyOptions()).thenReturn(nettyOptions);
// Config:
when(defaultProfile.getBoolean(DefaultDriverOption.REQUEST_WARN_IF_SET_KEYSPACE)).thenReturn(true);
when(defaultProfile.getBoolean(DefaultDriverOption.REPREPARE_ENABLED)).thenReturn(false);
when(defaultProfile.isDefined(DefaultDriverOption.PROTOCOL_VERSION)).thenReturn(true);
when(defaultProfile.getDuration(DefaultDriverOption.METADATA_TOPOLOGY_WINDOW)).thenReturn(Duration.ZERO);
when(defaultProfile.getInt(DefaultDriverOption.METADATA_TOPOLOGY_MAX_EVENTS)).thenReturn(1);
when(config.getDefaultProfile()).thenReturn(defaultProfile);
when(context.getConfig()).thenReturn(config);
// Init sequence:
when(metadataManager.refreshNodes()).thenReturn(CompletableFuture.completedFuture(null));
when(metadataManager.refreshSchema(null, false, true)).thenReturn(CompletableFuture.completedFuture(null));
when(context.getMetadataManager()).thenReturn(metadataManager);
when(topologyMonitor.init()).thenReturn(CompletableFuture.completedFuture(null));
when(context.getTopologyMonitor()).thenReturn(topologyMonitor);
when(context.getLoadBalancingPolicyWrapper()).thenReturn(loadBalancingPolicyWrapper);
when(context.getConfigLoader()).thenReturn(configLoader);
when(context.getMetricsFactory()).thenReturn(metricsFactory);
// Runtime behavior:
when(context.getSessionName()).thenReturn("test");
when(context.getChannelPoolFactory()).thenReturn(channelPoolFactory);
eventBus = spy(new EventBus("test"));
when(context.getEventBus()).thenReturn(eventBus);
node1 = mockLocalNode(1);
node2 = mockLocalNode(2);
node3 = mockLocalNode(3);
@SuppressWarnings("ConstantConditions") ImmutableMap<UUID, Node> nodes = ImmutableMap.of(node1.getHostId(), node1, node2.getHostId(), node2, node3.getHostId(), node3);
when(metadata.getNodes()).thenReturn(nodes);
when(metadataManager.getMetadata()).thenReturn(metadata);
PoolManager poolManager = new PoolManager(context);
when(context.getPoolManager()).thenReturn(poolManager);
// Shutdown sequence:
when(context.getReconnectionPolicy()).thenReturn(reconnectionPolicy);
when(context.getRetryPolicy(DriverExecutionProfile.DEFAULT_NAME)).thenReturn(retryPolicy);
when(context.getSpeculativeExecutionPolicies()).thenReturn(ImmutableMap.of(DriverExecutionProfile.DEFAULT_NAME, speculativeExecutionPolicy));
when(context.getAddressTranslator()).thenReturn(addressTranslator);
when(context.getNodeStateListener()).thenReturn(nodeStateListener);
when(context.getSchemaChangeListener()).thenReturn(schemaChangeListener);
when(context.getRequestTracker()).thenReturn(requestTracker);
when(metadataManager.closeAsync()).thenReturn(CompletableFuture.completedFuture(null));
when(metadataManager.forceCloseAsync()).thenReturn(CompletableFuture.completedFuture(null));
when(topologyMonitor.closeAsync()).thenReturn(CompletableFuture.completedFuture(null));
when(topologyMonitor.forceCloseAsync()).thenReturn(CompletableFuture.completedFuture(null));
when(context.getControlConnection()).thenReturn(controlConnection);
when(controlConnection.closeAsync()).thenReturn(CompletableFuture.completedFuture(null));
when(controlConnection.forceCloseAsync()).thenReturn(CompletableFuture.completedFuture(null));
DefaultPromise<Void> nettyCloseFuture = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);
nettyCloseFuture.setSuccess(null);
when(nettyOptions.onClose()).thenAnswer(invocation -> nettyCloseFuture);
}
use of com.datastax.oss.driver.internal.core.context.EventBus in project java-driver by datastax.
the class PoolManagerTest method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
DefaultEventLoopGroup adminEventLoopGroup = new DefaultEventLoopGroup(1);
when(nettyOptions.adminEventExecutorGroup()).thenReturn(adminEventLoopGroup);
when(context.getNettyOptions()).thenReturn(nettyOptions);
when(context.getEventBus()).thenReturn(new EventBus("test"));
when(config.getDefaultProfile()).thenReturn(defaultProfile);
when(context.getConfig()).thenReturn(config);
}
use of com.datastax.oss.driver.internal.core.context.EventBus in project java-driver by datastax.
the class EventBusTest method setup.
@Before
public void setup() {
bus = new EventBus("test");
results = new HashMap<>();
}
use of com.datastax.oss.driver.internal.core.context.EventBus in project java-driver by datastax.
the class ChannelPoolTestBase method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
adminEventLoopGroup = new DefaultEventLoopGroup(1);
when(context.getNettyOptions()).thenReturn(nettyOptions);
when(nettyOptions.adminEventExecutorGroup()).thenReturn(adminEventLoopGroup);
when(context.getConfig()).thenReturn(config);
when(config.getDefaultProfile()).thenReturn(defaultProfile);
this.eventBus = spy(new EventBus("test"));
when(context.getEventBus()).thenReturn(eventBus);
when(context.getChannelFactory()).thenReturn(channelFactory);
when(context.getReconnectionPolicy()).thenReturn(reconnectionPolicy);
when(reconnectionPolicy.newNodeSchedule(any(Node.class))).thenReturn(reconnectionSchedule);
// By default, set a large reconnection delay. Tests that care about reconnection will override
// it.
when(reconnectionSchedule.nextDelay()).thenReturn(Duration.ofDays(1));
when(context.getMetricsFactory()).thenReturn(metricsFactory);
when(metricsFactory.newNodeUpdater(any(Node.class))).thenReturn(nodeMetricUpdater);
node = TestNodeFactory.newNode(1, context);
}
Aggregations