-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use atomic timestamp for sensitive tests. (#147)
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ate53/src/test/java/com/hazelcast/hibernate/local/AtomicTimedLocalCacheRegionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |