Search in sources :

Example 21 with Category

use of org.junit.experimental.categories.Category in project hazelcast by hazelcast.

the class EvictionTest method testExpiration_onBackupPartitions_whenPuttingWithTTL.

@Test
@Category(NightlyTest.class)
public void testExpiration_onBackupPartitions_whenPuttingWithTTL() throws Exception {
    String mapName = randomMapName();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] nodes = factory.newInstances(getConfig());
    IMap<Integer, Integer> map = nodes[0].getMap(mapName);
    // 1. put keys with TTL.
    for (int i = 0; i < 60; i++) {
        map.put(i, i, 5, TimeUnit.SECONDS);
    }
    // 2. Shutdown one node.
    // Since we want to see previous backup partitions as owners.
    nodes[1].shutdown();
    // 3. Background task should sweep all keys.
    assertSizeEventually(0, map, 240);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Category(org.junit.experimental.categories.Category) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with Category

use of org.junit.experimental.categories.Category in project hazelcast by hazelcast.

the class WriteBehindOnBackupsTest method testPutTransientDoesNotStoreEntry_onPromotedReplica.

@Test
@Category(SlowTest.class)
public void testPutTransientDoesNotStoreEntry_onPromotedReplica() {
    String mapName = randomMapName();
    final MapStoreWithCounter<String, Object> mapStore = new MapStoreWithCounter<String, Object>();
    TestMapUsingMapStoreBuilder<String, Object> storeBuilder = TestMapUsingMapStoreBuilder.create();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final IMap<String, Object> map = storeBuilder.mapName(mapName).withMapStore(mapStore).withNodeCount(2).withNodeFactory(factory).withWriteDelaySeconds(5).withBackupCount(1).withPartitionCount(1).withBackupProcessingDelay(1).build();
    String key = UUID.randomUUID().toString();
    map.putTransient(key, 1, 1, TimeUnit.DAYS);
    killKeyOwner(key, storeBuilder);
    sleepSeconds(10);
    assertEquals("There should not be any store operation on promoted replica", 0, mapStore.countStore.get());
}
Also used : TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Category(org.junit.experimental.categories.Category) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with Category

use of org.junit.experimental.categories.Category in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method testWriteBehindDestroy.

@Test(timeout = 120000)
@Category(NightlyTest.class)
public // issue #2747: when MapStore configured with write behind, distributed objects' destroy method does not work
void testWriteBehindDestroy() throws InterruptedException {
    final int writeDelaySeconds = 5;
    String mapName = randomMapName();
    final MapStore<String, String> store = new SimpleMapStore<String, String>();
    Config config = newConfig(mapName, store, writeDelaySeconds);
    HazelcastInstance hzInstance = createHazelcastInstance(config);
    IMap<String, String> map = hzInstance.getMap(mapName);
    map.put("key", "value");
    map.destroy();
    sleepSeconds(2 * writeDelaySeconds);
    assertNotEquals("value", store.load("key"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) SimpleMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.SimpleMapStore) Category(org.junit.experimental.categories.Category) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with Category

use of org.junit.experimental.categories.Category in project hazelcast by hazelcast.

the class TopicTest method testTopicMultiThreading.

@Test
@Category(NightlyTest.class)
@SuppressWarnings("unchecked")
public void testTopicMultiThreading() throws Exception {
    final int nodeCount = 5;
    final int count = 1000;
    final String randomTopicName = randomString();
    Config config = new Config();
    config.getTopicConfig(randomTopicName).setGlobalOrderingEnabled(false);
    config.getTopicConfig(randomTopicName).setMultiThreadingEnabled(true);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance[] instances = factory.newInstances(config);
    final Set<String>[] threads = new Set[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        threads[i] = new HashSet<String>();
    }
    final CountDownLatch startLatch = new CountDownLatch(nodeCount);
    final CountDownLatch messageLatch = new CountDownLatch(nodeCount * nodeCount * count);
    final CountDownLatch publishLatch = new CountDownLatch(nodeCount * count);
    ExecutorService ex = Executors.newFixedThreadPool(nodeCount);
    for (int i = 0; i < nodeCount; i++) {
        final int finalI = i;
        ex.execute(new Runnable() {

            public void run() {
                final Set<String> thNames = threads[finalI];
                HazelcastInstance hz = instances[finalI];
                ITopic<TestMessage> topic = hz.getTopic(randomTopicName);
                topic.addMessageListener(new MessageListener<TestMessage>() {

                    public void onMessage(Message<TestMessage> message) {
                        thNames.add(Thread.currentThread().getName());
                        messageLatch.countDown();
                    }
                });
                startLatch.countDown();
                try {
                    startLatch.await(1, TimeUnit.MINUTES);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    return;
                }
                Member localMember = hz.getCluster().getLocalMember();
                for (int j = 0; j < count; j++) {
                    topic.publish(new TestMessage(localMember, UuidUtil.newUnsecureUuidString()));
                    publishLatch.countDown();
                }
            }
        });
    }
    try {
        assertTrue(publishLatch.await(2, TimeUnit.MINUTES));
        assertTrue(messageLatch.await(5, TimeUnit.MINUTES));
        boolean passed = false;
        for (int i = 0; i < nodeCount; i++) {
            if (threads[i].size() > 1) {
                passed = true;
            }
        }
        assertTrue("All listeners received messages in single thread. Expecting more threads involved", passed);
    } finally {
        ex.shutdownNow();
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ITopic(com.hazelcast.core.ITopic) Message(com.hazelcast.core.Message) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) MessageListener(com.hazelcast.core.MessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorService(java.util.concurrent.ExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) Category(org.junit.experimental.categories.Category) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with Category

use of org.junit.experimental.categories.Category in project beam by apache.

the class GroupByKeyTest method testTimestampCombinerLatest.

/**
   * Tests that when two elements are combined via a GroupByKey their output timestamp agrees
   * with the windowing function customized to use the latest value.
   */
@Test
@Category(ValidatesRunner.class)
public void testTimestampCombinerLatest() {
    p.apply(Create.timestamped(TimestampedValue.of(KV.of(0, "hello"), new Instant(0)), TimestampedValue.of(KV.of(0, "goodbye"), new Instant(10)))).apply(Window.<KV<Integer, String>>into(FixedWindows.of(Duration.standardMinutes(10))).withTimestampCombiner(TimestampCombiner.LATEST)).apply(GroupByKey.<Integer, String>create()).apply(ParDo.of(new AssertTimestamp(new Instant(10))));
    p.run();
}
Also used : Instant(org.joda.time.Instant) KV(org.apache.beam.sdk.values.KV) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

Category (org.junit.experimental.categories.Category)479 Test (org.junit.Test)476 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)148 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)121 File (java.io.File)68 VM (org.apache.geode.test.dunit.VM)65 KV (org.apache.beam.sdk.values.KV)62 Instant (org.joda.time.Instant)60 ArrayList (java.util.ArrayList)52 Matchers.containsString (org.hamcrest.Matchers.containsString)49 StringUtils.byteArrayToJsonString (org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString)41 Region (org.apache.geode.cache.Region)35 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)34 Host (org.apache.geode.test.dunit.Host)34 Properties (java.util.Properties)32 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)31 Cache (org.apache.geode.cache.Cache)26 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)25 IOException (java.io.IOException)24 CacheException (org.apache.geode.cache.CacheException)24