/** * Ensures that executing a query causing a schema change with a Cluster that has schema metadata * disabled will still wait on schema agreement, but not refresh the schema. * * @jira_ticket JAVA-858 * @since 2.0.11 */ @Test(groups = "short", dataProvider = "existingKeyspaceName") public void should_not_refresh_schema_on_schema_change_response(String keyspace) throws InterruptedException { ResultSet rs = schemaDisabledSession.execute(String.format(CREATE_TABLE, keyspace)); // Should still wait on schema agreement. assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue(); assertThat(schemaDisabledCluster.getMetadata().checkSchemaAgreement()).isTrue(); // Wait up to 1 second (since refreshSchema submitted in an executor) and check that // refreshSchema never called. verify(schemaDisabledControlConnection, after(1000).never()) .refreshSchema( any(SchemaElement.class), any(String.class), any(String.class), anyListOf(String.class)); }
/** * Ensures that if the core connection pool is full that borrowConnection will create and use a * new connection. * * @jira_ticket JAVA-419 * @test_category connection:connection_pool * @since 2.0.10, 2.1.6 */ @Test(groups = "short") public void should_add_extra_connection_when_core_full() throws Exception { Cluster cluster = createClusterBuilder().build(); List<MockRequest> allRequests = newArrayList(); try { HostConnectionPool pool = createPool(cluster, 1, 2); Connection.Factory factory = spy(cluster.manager.connectionFactory); cluster.manager.connectionFactory = factory; Connection core = pool.connections.get(0); // Fill core connection + 1 List<MockRequest> requests = MockRequest.sendMany(NEW_CONNECTION_THRESHOLD, pool); assertBorrowedConnection(requests, core); allRequests.addAll(requests); allRequests.add(MockRequest.send(pool)); // Reaching the threshold should have triggered the creation of an extra one verify(factory, after(2000).times(1)).open(any(HostConnectionPool.class)); assertPoolSize(pool, 2); } finally { MockRequest.completeAll(allRequests); cluster.close(); } }
allRequests.add(MockRequest.send(pool)); verify(factory, after(2000).times(1)).open(any(HostConnectionPool.class)); assertThat(pool.connections).hasSize(2);
verify(factory, after(2000).times(1)).open(any(HostConnectionPool.class)); assertPoolSize(pool, 2);
allRequests.add(MockRequest.send(pool)); verify(factory, after(2000).times(1)).open(any(HostConnectionPool.class)); assertPoolSize(pool, 2); reset(factory); allRequests.add(MockRequest.send(pool)); assertThat(connection2.inFlight.get()).isEqualTo(101); verify(factory, after(2000).times(1)).open(any(HostConnectionPool.class)); assertPoolSize(pool, 2);
allRequests.add(MockRequest.send(pool)); verify(factory, after(2000).times(1)).open(any(HostConnectionPool.class)); assertThat(pool.connections).hasSize(2);
verify(factory, after((reconnectInterval + readTimeout) * 2).never()) .open(any(HostConnectionPool.class)); } finally {
verify(factory, after(reconnectInterval * 2).atLeast(2)).open(host);
@Test public void ignoreChangesOutsideObservedPath() throws Exception { // Given ObservationUtil.registerChangeListener(WEBSITE, "/a", listener); // When session.getNode("/b").addNode("b1", NodeTypes.ContentNode.NAME); session.save(); // Then verify(callback, after(TIMEOUT).never()).processEvent(anyInt(), anyString()); }
@Test public void ignoreChangesOutsideObservedPath() throws Exception { // GIVEN WorkspaceEventListenerRegistration.Handle handle = WorkspaceEventListenerRegistration.observe(WEBSITE, "/a", listener).register(); // WHEN session.getNode("/b").addNode("b1", NodeTypes.ContentNode.NAME); session.save(); // THEN verify(callback, after(TIMEOUT).never()).processEvent(anyInt(), anyString()); // cleanup handle.unregister(); }
@Test default void registerShouldNotDispatchPastEventsInDistributedContext() throws Exception { MailboxListener listener = newListener(); eventBus2().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); eventBus().register(listener, KEY_1); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void registerShouldNotDispatchPastEvents() throws Exception { MailboxListener listener = newListener(); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); eventBus().register(listener, KEY_1); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void unregisteredDistantListenersShouldNotBeNotified() throws Exception { MailboxListener mailboxListener = newListener(); eventBus().register(mailboxListener, KEY_1).unregister(); eventBus2().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); verify(mailboxListener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void unregisteredGroupListenerShouldNotReceiveEvents() throws Exception { MailboxListener listener = newListener(); Registration registration = eventBus().register(listener, GROUP_A); registration.unregister(); eventBus().dispatch(EVENT, NO_KEYS).block(); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void dispatchShouldNotifyOnlyRegisteredListener() throws Exception { MailboxListener listener = newListener(); MailboxListener listener2 = newListener(); eventBus().register(listener, KEY_1); eventBus().register(listener2, KEY_2); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); verify(listener, timeout(ONE_SECOND.toMillis()).times(1)).event(any()); verify(listener2, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void groupListenersShouldNotReceiveNoopEvents() throws Exception { MailboxListener listener = newListener(); eventBus().register(listener, GROUP_A); MailboxListener.Added noopEvent = new MailboxListener.Added(MailboxSession.SessionId.of(18), User.fromUsername("bob"), MailboxPath.forUser("bob", "mailbox"), TestId.of(58), ImmutableSortedMap.of(), Event.EventId.random()); eventBus().dispatch(noopEvent, NO_KEYS).block(); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }
@Test default void registeredListenersShouldNotReceiveNoopEvents() throws Exception { MailboxListener listener = newListener(); eventBus().register(listener, KEY_1); MailboxListener.Added noopEvent = new MailboxListener.Added(MailboxSession.SessionId.of(18), User.fromUsername("bob"), MailboxPath.forUser("bob", "mailbox"), TestId.of(58), ImmutableSortedMap.of(), Event.EventId.random()); eventBus().dispatch(noopEvent, KEY_1).block(); verify(listener, after(FIVE_HUNDRED_MS.toMillis()).never()) .event(any()); }