Search in sources :

Example 91 with Timeout

use of org.junit.rules.Timeout in project rxrabbit by meltwater.

the class RxRabbitTests method can_handle_publish_confirms_after_connection_error.

@Test
public void can_handle_publish_confirms_after_connection_error() throws IOException {
    ChannelFactory proxyChannelFactory = getDroppingAndExceptionThrowingChannelFactory(1, 2);
    final PublisherSettings proxyPublishSettings = new PublisherSettings().withNumChannels(1).withPublisherConfirms(true).withRetryCount(5).withPublishTimeoutSecs(1);
    DefaultPublisherFactory proxyPublishFactory = new DefaultPublisherFactory(proxyChannelFactory, proxyPublishSettings);
    RabbitPublisher publisher = proxyPublishFactory.createPublisher();
    final List<PublishedMessage> res = sendNMessagesAsync(3, 0, publisher).take(3).timeout(30, TimeUnit.SECONDS).toList().toBlocking().last();
    for (PublishedMessage re : res) {
        assertFalse(re.failed);
    }
    final List<Message> consumeRes = consumerFactory.createConsumer(inputQueue).doOnNext(m -> m.acknowledger.ack()).take(3).timeout(10, TimeUnit.SECONDS).toList().toBlocking().last();
    assertThat(consumeRes.size(), is(3));
    publisher.close();
}
Also used : SortedSet(java.util.SortedSet) DockerContainers(com.meltwater.rxrabbit.docker.DockerContainers) TimeoutException(java.util.concurrent.TimeoutException) Random(java.util.Random) Collections2(com.google.common.collect.Collections2) MonitoringTestThreadFactory(com.meltwater.rxrabbit.util.MonitoringTestThreadFactory) Assert.assertThat(org.junit.Assert.assertThat) RabbitTestUtils.waitForNumQueuesToBePresent(com.meltwater.rxrabbit.RabbitTestUtils.waitForNumQueuesToBePresent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) RxJavaHooks(rx.plugins.RxJavaHooks) TakeAndAckTransformer(com.meltwater.rxrabbit.util.TakeAndAckTransformer) AfterClass(org.junit.AfterClass) Collection(java.util.Collection) Set(java.util.Set) RabbitTestUtils.declareAndBindQueue(com.meltwater.rxrabbit.RabbitTestUtils.declareAndBindQueue) Scheduler(rx.Scheduler) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) DefaultChannelFactory(com.meltwater.rxrabbit.impl.DefaultChannelFactory) RabbitTestUtils.realm(com.meltwater.rxrabbit.RabbitTestUtils.realm) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) CachedThreadScheduler(rx.internal.schedulers.CachedThreadScheduler) Subscription(rx.Subscription) RabbitTestUtils.waitForAllConnectionsToClose(com.meltwater.rxrabbit.RabbitTestUtils.waitForAllConnectionsToClose) RabbitTestUtils.createQueues(com.meltwater.rxrabbit.RabbitTestUtils.createQueues) BeforeClass(org.junit.BeforeClass) ConfirmListener(com.rabbitmq.client.ConfirmListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) MINUTES(java.util.concurrent.TimeUnit.MINUTES) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeSet(java.util.TreeSet) Observable(rx.Observable) ArrayList(java.util.ArrayList) ConstantBackoffAlgorithm(com.meltwater.rxrabbit.util.ConstantBackoffAlgorithm) HashSet(java.util.HashSet) AsyncHttpClient(com.ning.http.client.AsyncHttpClient) Timeout(org.junit.rules.Timeout) Matchers.lessThan(org.hamcrest.Matchers.lessThan) Response(com.ning.http.client.Response) Before(org.junit.Before) ExampleCode(com.meltwater.rxrabbit.example.ExampleCode) Subscriber(rx.Subscriber) Semaphore(java.util.concurrent.Semaphore) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Logger(com.meltwater.rxrabbit.util.Logger) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AMQP(com.rabbitmq.client.AMQP) DefaultChannelFactory(com.meltwater.rxrabbit.impl.DefaultChannelFactory) Test(org.junit.Test)

Example 92 with Timeout

use of org.junit.rules.Timeout in project ignite by apache.

the class LoadTest method testMultithreading.

/**
 * Test thin client in multi-thread environment.
 */
@Test
public void testMultithreading() throws Exception {
    final int THREAD_CNT = 8;
    final int ITERATION_CNT = 20;
    final int BATCH_SIZE = 1000;
    final int PAGE_CNT = 3;
    IgniteConfiguration srvCfg = Config.getServerConfiguration();
    // No peer class loading from thin clients: we need the server to know about this class to deserialize
    // ScanQuery filter.
    srvCfg.setBinaryConfiguration(new BinaryConfiguration().setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(getClass().getName()), new BinaryTypeConfiguration(SerializedLambda.class.getName()))));
    try (Ignite ignored = Ignition.start(srvCfg);
        IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
        ClientCache<Integer, String> cache = client.createCache("testMultithreading");
        AtomicInteger cnt = new AtomicInteger(1);
        AtomicReference<Throwable> error = new AtomicReference<>();
        Runnable assertion = () -> {
            try {
                int rangeStart = cnt.getAndAdd(BATCH_SIZE);
                int rangeEnd = rangeStart + BATCH_SIZE;
                Map<Integer, String> data = IntStream.range(rangeStart, rangeEnd).boxed().collect(Collectors.toMap(i -> i, i -> String.format("String %s", i)));
                cache.putAll(data);
                Query<Cache.Entry<Integer, String>> qry = new ScanQuery<Integer, String>().setPageSize(data.size() / PAGE_CNT).setFilter((i, s) -> i >= rangeStart && i < rangeEnd);
                try (QueryCursor<Cache.Entry<Integer, String>> cur = cache.query(qry)) {
                    List<Cache.Entry<Integer, String>> res = cur.getAll();
                    assertEquals("Unexpected number of entries", data.size(), res.size());
                    Map<Integer, String> act = res.stream().collect(Collectors.toMap(Cache.Entry::getKey, Cache.Entry::getValue));
                    assertEquals("Unexpected entries", data, act);
                }
            } catch (Throwable ex) {
                error.set(ex);
            }
        };
        CountDownLatch complete = new CountDownLatch(THREAD_CNT);
        Runnable manyAssertions = () -> {
            for (int i = 0; i < ITERATION_CNT && error.get() == null; i++) assertion.run();
            complete.countDown();
        };
        ExecutorService threadPool = Executors.newFixedThreadPool(THREAD_CNT);
        IntStream.range(0, THREAD_CNT).forEach(t -> threadPool.submit(manyAssertions));
        assertTrue("Timeout", complete.await(180, TimeUnit.SECONDS));
        String errMsg = error.get() == null ? "" : error.get().getMessage();
        assertNull(errMsg, error.get());
    }
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) AtomicReference(java.util.concurrent.atomic.AtomicReference) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializedLambda(java.lang.invoke.SerializedLambda) Map(java.util.Map) Cache(javax.cache.Cache) Timeout(org.junit.rules.Timeout) ExecutorService(java.util.concurrent.ExecutorService) Query(org.apache.ignite.cache.query.Query) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) Rule(org.junit.Rule) Assert.assertNull(org.junit.Assert.assertNull) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) QueryCursor(org.apache.ignite.cache.query.QueryCursor) ScanQuery(org.apache.ignite.cache.query.ScanQuery) Assert.assertEquals(org.junit.Assert.assertEquals) Query(org.apache.ignite.cache.query.Query) ScanQuery(org.apache.ignite.cache.query.ScanQuery) Ignite(org.apache.ignite.Ignite) List(java.util.List) QueryCursor(org.apache.ignite.cache.query.QueryCursor) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) Map(java.util.Map) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Aggregations

Timeout (org.junit.rules.Timeout)92 Rule (org.junit.Rule)91 Test (org.junit.Test)91 Assert (org.junit.Assert)84 AssertExtensions (io.pravega.test.common.AssertExtensions)81 Duration (java.time.Duration)81 ArrayList (java.util.ArrayList)80 lombok.val (lombok.val)79 TimeUnit (java.util.concurrent.TimeUnit)78 ThreadPooledTestSuite (io.pravega.test.common.ThreadPooledTestSuite)77 Cleanup (lombok.Cleanup)73 Collections (java.util.Collections)72 CompletableFuture (java.util.concurrent.CompletableFuture)72 HashMap (java.util.HashMap)69 ByteArraySegment (io.pravega.common.util.ByteArraySegment)68 Collectors (java.util.stream.Collectors)68 List (java.util.List)66 AtomicReference (java.util.concurrent.atomic.AtomicReference)66 IntentionalException (io.pravega.test.common.IntentionalException)62 Map (java.util.Map)62