Search in sources :

Example 1 with AtLeast

use of org.mockito.internal.verification.AtLeast in project x-pipe by ctripcorp.

the class OneThreadTaskExecutorTest method testClose.

@Test
public void testClose() throws Exception {
    CommandFuture<Void> future = new DefaultCommandFuture<>();
    when(command.execute()).thenReturn(future);
    future.setFailure(new Exception());
    RetryCommandFactory<Void> retryCommandFactory = DefaultRetryCommandFactory.retryForever(scheduled, 0);
    OneThreadTaskExecutor oneThreadTaskExecutor = new OneThreadTaskExecutor(retryCommandFactory, executors);
    oneThreadTaskExecutor.executeCommand(command);
    sleep(100);
    logger.info("[testClose][destroy]");
    oneThreadTaskExecutor.destroy();
    retryCommandFactory.destroy();
    sleep(50);
    verify(command, new AtLeast(1)).execute();
    verify(command, new AtLeast(1)).reset();
    logger.info("[testClose][sleep verify no more interactions]");
    sleep(100);
    verifyNoMoreInteractions(command);
}
Also used : DefaultCommandFuture(com.ctrip.xpipe.command.DefaultCommandFuture) AtLeast(org.mockito.internal.verification.AtLeast) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 2 with AtLeast

use of org.mockito.internal.verification.AtLeast in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_CustomDiscoveryService_whenDiscoveredNodes_isEmpty.

@Test
public void test_CustomDiscoveryService_whenDiscoveredNodes_isEmpty() {
    ClientConfig config = new ClientConfig();
    config.setProperty(ClusterProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    final DiscoveryService discoveryService = mock(DiscoveryService.class);
    when(discoveryService.discoverNodes()).thenReturn(Collections.emptyList());
    DiscoveryServiceProvider discoveryServiceProvider = arg0 -> discoveryService;
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    config.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(0);
    networkConfig.getDiscoveryConfig().addDiscoveryStrategyConfig(new DiscoveryStrategyConfig());
    networkConfig.getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
    try {
        HazelcastClient.newHazelcastClient(config);
    } catch (IllegalStateException expected) {
    // no server available
    }
    verify(discoveryService, new AtLeast(1)).discoverNodes();
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) Address(com.hazelcast.cluster.Address) QuickTest(com.hazelcast.test.annotation.QuickTest) URL(java.net.URL) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) AtLeast(org.mockito.internal.verification.AtLeast) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) After(org.junit.After) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) Logger(com.hazelcast.logging.Logger) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) Category(org.junit.experimental.categories.Category) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Hazelcast(com.hazelcast.core.Hazelcast) NodeFilter(com.hazelcast.spi.discovery.NodeFilter) DiscoveryMode(com.hazelcast.spi.discovery.integration.DiscoveryMode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Mockito.mock(org.mockito.Mockito.mock) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) HazelcastClient(com.hazelcast.client.HazelcastClient) PartitionGroupStrategy(com.hazelcast.spi.partitiongroup.PartitionGroupStrategy) StreamSource(javax.xml.transform.stream.StreamSource) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Source(javax.xml.transform.Source) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) Schema(javax.xml.validation.Schema) ArrayList(java.util.ArrayList) JoinConfig(com.hazelcast.config.JoinConfig) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) ILogger(com.hazelcast.logging.ILogger) DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) ClientClasspathXmlConfig(com.hazelcast.client.config.ClientClasspathXmlConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) XMLConstants(javax.xml.XMLConstants) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SchemaFactory(javax.xml.validation.SchemaFactory) PropertyTypeConverter(com.hazelcast.config.properties.PropertyTypeConverter) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) Test(org.junit.Test) Validator(javax.xml.validation.Validator) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) SlowTest(com.hazelcast.test.annotation.SlowTest) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) Mockito.verify(org.mockito.Mockito.verify) AbstractDiscoveryStrategy(com.hazelcast.spi.discovery.AbstractDiscoveryStrategy) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) AtLeast(org.mockito.internal.verification.AtLeast) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

AbstractTest (com.ctrip.xpipe.AbstractTest)1 DefaultCommandFuture (com.ctrip.xpipe.command.DefaultCommandFuture)1 HazelcastClient (com.hazelcast.client.HazelcastClient)1 ClientClasspathXmlConfig (com.hazelcast.client.config.ClientClasspathXmlConfig)1 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)1 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)1 Address (com.hazelcast.cluster.Address)1 Config (com.hazelcast.config.Config)1 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)1 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)1 InterfacesConfig (com.hazelcast.config.InterfacesConfig)1 JoinConfig (com.hazelcast.config.JoinConfig)1 PropertyDefinition (com.hazelcast.config.properties.PropertyDefinition)1 PropertyTypeConverter (com.hazelcast.config.properties.PropertyTypeConverter)1 SimplePropertyDefinition (com.hazelcast.config.properties.SimplePropertyDefinition)1 Hazelcast (com.hazelcast.core.Hazelcast)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ILogger (com.hazelcast.logging.ILogger)1 Logger (com.hazelcast.logging.Logger)1