Skip to content

Commit

Permalink
Use atomic timestamp for sensitive tests. (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
enozcan authored May 18, 2020
1 parent d96a1d4 commit 1fd6789
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.hibernate.entity.DummyEntity;
import com.hazelcast.hibernate.local.AtomicTimedLocalCacheRegionFactory;
import com.hazelcast.test.HazelcastSerialClassRunner;
import com.hazelcast.test.annotation.ParallelJVMTest;
import com.hazelcast.test.annotation.QuickTest;
Expand All @@ -42,7 +43,7 @@ public class LocalRegionFactoryDefaultTest extends RegionFactoryDefaultTest {

protected Properties getCacheProperties() {
Properties props = new Properties();
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastLocalCacheRegionFactory.class.getName());
props.setProperty(Environment.CACHE_REGION_FACTORY, AtomicTimedLocalCacheRegionFactory.class.getName());
return props;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.hazelcast.hibernate.local;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.hibernate.HazelcastLocalCacheRegionFactory;
import org.hibernate.cache.spi.CacheKeysFactory;

import java.util.concurrent.atomic.AtomicLong;

/**
* This class just extends HazelcastLocalCacheRegionFactory to ensure that consecutive timestamps are
* different and in an increasing manner. Cluster#getClusterTime() may fall short to provide different
* timestamps when it is called repeatedly and in such a case test results become inconsistent.
*/
public class AtomicTimedLocalCacheRegionFactory extends HazelcastLocalCacheRegionFactory {

private final AtomicLong epoch = new AtomicLong(1);

public AtomicTimedLocalCacheRegionFactory() {
super();
}

public AtomicTimedLocalCacheRegionFactory(final CacheKeysFactory cacheKeysFactory) {
super(cacheKeysFactory);
}

public AtomicTimedLocalCacheRegionFactory(final HazelcastInstance instance) {
super(instance);
}

@Override
public long nextTimestamp() {
return epoch.getAndIncrement();
}
}

0 comments on commit 1fd6789

Please sign in to comment.