diff --git a/hazelcast-client/src/main/java/com/hazelcast/client/proxy/ClientMapProxy.java b/hazelcast-client/src/main/java/com/hazelcast/client/proxy/ClientMapProxy.java index 5bff43066689..0bd3f9b093e2 100644 --- a/hazelcast-client/src/main/java/com/hazelcast/client/proxy/ClientMapProxy.java +++ b/hazelcast-client/src/main/java/com/hazelcast/client/proxy/ClientMapProxy.java @@ -126,7 +126,6 @@ import com.hazelcast.map.impl.querycache.subscriber.QueryCacheEndToEndProvider; import com.hazelcast.map.impl.querycache.subscriber.QueryCacheRequest; import com.hazelcast.map.impl.querycache.subscriber.SubscriberContext; -import com.hazelcast.map.impl.recordstore.RecordStore; import com.hazelcast.map.journal.EventJournalMapEvent; import com.hazelcast.map.listener.MapListener; import com.hazelcast.map.listener.MapPartitionLostListener; @@ -176,7 +175,6 @@ import static com.hazelcast.util.CollectionUtil.objectToDataCollection; import static com.hazelcast.util.ExceptionUtil.rethrow; import static com.hazelcast.util.MapUtil.createHashMap; -import static com.hazelcast.util.Preconditions.checkMinTimeIfPositive; import static com.hazelcast.util.Preconditions.checkNotInstanceOf; import static com.hazelcast.util.Preconditions.checkNotNull; import static com.hazelcast.util.SortingUtil.getSortedQueryResultSet; @@ -204,9 +202,6 @@ public class ClientMapProxy extends ClientProxy protected static final String NULL_AGGREGATOR_IS_NOT_ALLOWED = "Aggregator should not be null!"; protected static final String NULL_PROJECTION_IS_NOT_ALLOWED = "Projection should not be null!"; - protected static final String MAX_IDLE_TIME_IS_TOO_SMALL = "Parameter maxIdle in seconds representation must be greater than" - + " or equal to " + RecordStore.MIN_ALLOWED_MAX_IDLE; - @SuppressWarnings("unchecked") protected static final ClientMessageDecoder GET_ASYNC_RESPONSE_DECODER = new ClientMessageDecoder() { @Override @@ -343,8 +338,6 @@ public V put(K key, V value) { public V put(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) { checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); return putInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value); } @@ -454,8 +447,6 @@ public ICompletableFuture putAsync(K key, V value, long ttl, TimeUnit timeuni public ICompletableFuture putAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) { checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); return putAsyncInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value); } @@ -497,8 +488,6 @@ public ICompletableFuture setAsync(K key, V value, long ttl, TimeUnit time public ICompletableFuture setAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) { checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); return setAsyncInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value); } @@ -609,8 +598,6 @@ public void putTransient(K key, V value, long ttl, TimeUnit timeunit) { public void putTransient(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) { checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); putTransientInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value); } @@ -651,8 +638,6 @@ public V putIfAbsent(K key, V value, long ttl, TimeUnit timeunit) { public V putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) { checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); return putIfAbsentInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value); } @@ -723,8 +708,6 @@ public void set(K key, V value, long ttl, TimeUnit timeunit) { public void set(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit) { checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, RecordStore.MIN_ALLOWED_MAX_IDLE, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); setInternal(ttl, ttlUnit, maxIdle, maxIdleUnit, key, value); } diff --git a/hazelcast-client/src/test/java/com/hazelcast/client/map/MapPreconditionsTest.java b/hazelcast-client/src/test/java/com/hazelcast/client/map/MapPreconditionsTest.java index 135680b14d2a..97872abf6c01 100644 --- a/hazelcast-client/src/test/java/com/hazelcast/client/map/MapPreconditionsTest.java +++ b/hazelcast-client/src/test/java/com/hazelcast/client/map/MapPreconditionsTest.java @@ -27,7 +27,6 @@ import com.hazelcast.map.EntryProcessor; import com.hazelcast.map.QueryResultSizeExceededException; import com.hazelcast.map.impl.MapListenerAdapter; -import com.hazelcast.map.impl.recordstore.RecordStore; import com.hazelcast.map.listener.MapListener; import com.hazelcast.query.Predicate; import com.hazelcast.query.TruePredicate; @@ -49,7 +48,6 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; -import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertEquals; @RunWith(HazelcastParallelClassRunner.class) @@ -615,42 +613,6 @@ public void testIssue7631_emptyKeysSupported() { assertEquals(emptyMap(), res); } - @Test(expected = IllegalArgumentException.class) - public void testPutAsyncWithNotAllowedMaxIdleTime() { - map.putAsync("key1", "value1", 1, TimeUnit.MINUTES, - RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsyncWithNotAllowedMaxIdleTime() { - map.setAsync("key1", "value1", 1, TimeUnit.MINUTES, - RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testPutWithNotAllowedMaxIdleTime() { - map.put("key1", "value1", 1, TimeUnit.MINUTES, - RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testPutTransientWithNotAllowedMaxIdleTime() { - map.putTransient("key1", "value1", 1, TimeUnit.MINUTES, - RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testPutIfAbsentWithNotAllowedMaxIdleTime() { - map.putIfAbsent("key1", "value1", 1, TimeUnit.MINUTES, - RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetWithNotAllowedMaxIdleTime() { - map.set("key1", "value1", 1, TimeUnit.MINUTES, - RecordStore.MIN_ALLOWED_MAX_IDLE - 1, SECONDS); - } - private static class NoOpEntryProcessor implements EntryProcessor { @Override public Object process(Map.Entry entry) { diff --git a/hazelcast/src/main/java/com/hazelcast/config/MapConfig.java b/hazelcast/src/main/java/com/hazelcast/config/MapConfig.java index a7b4f58b80fd..555267a1e9e9 100644 --- a/hazelcast/src/main/java/com/hazelcast/config/MapConfig.java +++ b/hazelcast/src/main/java/com/hazelcast/config/MapConfig.java @@ -87,11 +87,6 @@ public class MapConfig implements SplitBrainMergeTypeProvider, IdentifiedDataSer */ public static final int DEFAULT_MAX_IDLE_SECONDS = 0; - /** - * The number of minimum and non-zero time to wait eviction in seconds. - */ - public static final int MIN_ALLOWED_MAX_IDLE_SECONDS = 2; - /** * Default policy for eviction. */ @@ -439,22 +434,13 @@ public int getMaxIdleSeconds() { * Maximum number of seconds for each entry to stay idle in the map. Entries that are * idle (not touched) for more than {@code maxIdleSeconds} will get automatically evicted from the map. * Entry is touched if {@code get()}, {@code getAll()}, {@code put()} or {@code containsKey()} is called. - * {@code 0} and any integer between {@value #MIN_ALLOWED_MAX_IDLE_SECONDS} and {@code Integer.MAX_VALUE} (inclusive) - * are allowed. - * {@code 0} means infinite. Default is {@code 0}. + * Any integer between {@code 0} and {@code Integer.MAX_VALUE}. + * {@code 0} means infinite. Default is {@code 0}. The time precision is limited by 1 second. The MaxIdle that + * less than 1 second can lead to unexpected behaviour. * * @param maxIdleSeconds the maxIdleSeconds (the maximum number of seconds for each entry to stay idle in the map) to set - * @throws IllegalArgumentException if maxIdleSeconds is negative or non-zero and less - * than {@value #MIN_ALLOWED_MAX_IDLE_SECONDS}. */ public MapConfig setMaxIdleSeconds(int maxIdleSeconds) { - if (maxIdleSeconds < 0) { - throw new IllegalArgumentException("Parameter maxIdleSeconds can not get a negative value"); - } - if (maxIdleSeconds != DEFAULT_MAX_IDLE_SECONDS && maxIdleSeconds < MIN_ALLOWED_MAX_IDLE_SECONDS) { - throw new IllegalArgumentException("Parameter maxIdleSeconds must be greater than or equal to " - + MIN_ALLOWED_MAX_IDLE_SECONDS); - } this.maxIdleSeconds = maxIdleSeconds; return this; } diff --git a/hazelcast/src/main/java/com/hazelcast/core/IMap.java b/hazelcast/src/main/java/com/hazelcast/core/IMap.java index 08d3b5da756a..cf3e0d470470 100644 --- a/hazelcast/src/main/java/com/hazelcast/core/IMap.java +++ b/hazelcast/src/main/java/com/hazelcast/core/IMap.java @@ -776,8 +776,8 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap { *

* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0, * then the entry lives forever. If the MaxIdle is negative, then the MaxIdle - * from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than - * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent. + * from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that + * less than 1 second can lead to unexpected behaviour. *

      *   ICompletableFuture future = map.putAsync(key, value, ttl, timeunit);
      *   // do some other stuff, when ready get the result
@@ -853,8 +853,6 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap {
      * @param maxIdleUnit time unit for the Max-Idle
      * @return ICompletableFuture from which the old value of the key can be retrieved
      * @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null
-     * @throws IllegalArgumentException if maxIdle is greater than zero and less
-     * than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent
      * @see ICompletableFuture
      * @see #setAsync(Object, Object, long, TimeUnit)
      */
@@ -933,10 +931,6 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap {
      * The entry will expire and get evicted after the TTL. If the TTL is 0,
      * then the entry lives forever. If the TTL is negative, then the TTL
      * from the map configuration will be used (default: forever).
-     * 

- * The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0, - * then the entry lives forever. If the MaxIdle is negative, then the MaxIdle - * from the map configuration will be used (default: forever). *

      *   ICompletableFuture<Void> future = map.setAsync(key, value, ttl, timeunit);
      *   // do some other stuff, when you want to make sure set operation is complete:
@@ -1010,12 +1004,12 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap {
      * 

* The entry will expire and get evicted after the TTL. If the TTL is 0, * then the entry lives forever. If the TTL is negative, then the TTL - * from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than - * * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent. + * from the map configuration will be used (default: forever). *

* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0, * then the entry lives forever. If the MaxIdle is negative, then the MaxIdle - * from the map configuration will be used (default: forever). + * from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that + * less than 1 second can lead to unexpected behaviour. *

      *   ICompletableFuture<Void> future = map.setAsync(key, value, ttl, timeunit);
      *   // do some other stuff, when you want to make sure set operation is complete:
@@ -1082,8 +1076,6 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap {
      * @return ICompletableFuture on which client code can block waiting for the operation to complete
      * or provide an {@link ExecutionCallback} to be invoked upon set operation completion
      * @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null
-     * @throws IllegalArgumentException if maxIdle is greater than zero and less
-     * than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent
      * @see ICompletableFuture
      */
     ICompletableFuture setAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit);
@@ -1254,8 +1246,8 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap {
      * 

* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0, * then the entry lives forever. If the MaxIdle is negative, then the MaxIdle - * from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than - * * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent. + * from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that + * less than 1 second can lead to unexpected behaviour. *

* Warning 1: *

@@ -1302,8 +1294,6 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap { * @param maxIdleUnit time unit for the Max-Idle * @return old value of the entry * @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null - * @throws IllegalArgumentException if maxIdle is greater than zero and less - * than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent */ V put(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit); @@ -1345,8 +1335,8 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap { *

* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0, * then the entry lives forever. If the MaxIdle is negative, then the MaxIdle - * from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than - * * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent. + * from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that + * less than 1 second can lead to unexpected behaviour. *

* Warning 1: *

@@ -1366,8 +1356,6 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap { * (0 means infinite, negative means map config default) * @param maxIdleUnit time unit for the Max-Idle * @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null - * @throws IllegalArgumentException if maxIdle is greater than zero and less - * than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent */ void putTransient(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit); @@ -1466,8 +1454,8 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap { *

* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0, * then the entry lives forever. If the MaxIdle is negative, then the MaxIdle - * from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than - * * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent. + * from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that + * less than 1 second can lead to unexpected behaviour. *

* Warning 1: *

@@ -1511,8 +1499,6 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap { * @param maxIdleUnit time unit for the Max-Idle * @return old value of the entry * @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null - * @throws IllegalArgumentException if maxIdle is greater than zero and less - * than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent */ V putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit); /** @@ -1665,8 +1651,8 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap { *

* The entry will expire and get evicted after the Max Idle time. If the MaxIdle is 0, * then the entry lives forever. If the MaxIdle is negative, then the MaxIdle - * from the map configuration will be used (default: forever). If the MaxIdle is positive, it must not be less than - * * {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent. + * from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that + * less than 1 second can lead to unexpected behaviour. *

* Warning 1: *

@@ -1699,8 +1685,6 @@ public interface IMap extends ConcurrentMap, LegacyAsyncMap { * (0 means infinite, negative means map config default) * @param maxIdleUnit time unit for the Max-Idle * @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are null - * @throws IllegalArgumentException if maxIdle is greater than zero and less - * than {@value com.hazelcast.config.MapConfig#MIN_ALLOWED_MAX_IDLE_SECONDS} in seconds equivalent */ void set(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit maxIdleUnit); diff --git a/hazelcast/src/main/java/com/hazelcast/map/impl/proxy/MapProxyImpl.java b/hazelcast/src/main/java/com/hazelcast/map/impl/proxy/MapProxyImpl.java index b2cd6436b2b5..d5693c5fe08d 100644 --- a/hazelcast/src/main/java/com/hazelcast/map/impl/proxy/MapProxyImpl.java +++ b/hazelcast/src/main/java/com/hazelcast/map/impl/proxy/MapProxyImpl.java @@ -91,7 +91,6 @@ import static com.hazelcast.map.impl.recordstore.RecordStore.DEFAULT_MAX_IDLE; import static com.hazelcast.util.ExceptionUtil.rethrow; import static com.hazelcast.util.MapUtil.createHashMap; -import static com.hazelcast.util.Preconditions.checkMinTimeIfPositive; import static com.hazelcast.util.Preconditions.checkNoNullInside; import static com.hazelcast.util.Preconditions.checkNotInstanceOf; import static com.hazelcast.util.Preconditions.checkNotNull; @@ -145,8 +144,6 @@ public V put(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUnit checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); Data valueData = toData(value); Data result = putInternal(key, valueData, ttl, ttlUnit, maxIdle, maxIdleUnit); @@ -186,8 +183,6 @@ public V putIfAbsent(K key, V value, long ttl, TimeUnit timeunit, long maxIdle, checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); Data valueData = toData(value); Data result = putIfAbsentInternal(key, valueData, ttl, timeunit, maxIdle, maxIdleUnit); @@ -212,8 +207,6 @@ public void putTransient(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdl checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); Data valueData = toData(value); putTransientInternal(key, valueData, ttl, ttlUnit, maxIdle, maxIdleUnit); @@ -262,8 +255,6 @@ public void set(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle, TimeUn checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); Data valueData = toData(value); setInternal(key, valueData, ttl, ttlUnit, maxIdle, maxIdleUnit); @@ -388,8 +379,6 @@ public ICompletableFuture putAsync(K key, V value, long ttl, TimeUnit ttlUnit checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); Data valueData = toData(value); return new DelegatingFuture( @@ -422,8 +411,6 @@ public ICompletableFuture setAsync(K key, V value, long ttl, TimeUnit ttlU checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED); checkNotNull(value, NULL_VALUE_IS_NOT_ALLOWED); - checkMinTimeIfPositive(maxIdle, maxIdleUnit, MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS, TimeUnit.SECONDS, - MAX_IDLE_TIME_IS_TOO_SMALL); Data valueData = toData(value); return new DelegatingFuture( diff --git a/hazelcast/src/main/java/com/hazelcast/map/impl/proxy/MapProxySupport.java b/hazelcast/src/main/java/com/hazelcast/map/impl/proxy/MapProxySupport.java index c8345bc415c6..c21afed482a2 100644 --- a/hazelcast/src/main/java/com/hazelcast/map/impl/proxy/MapProxySupport.java +++ b/hazelcast/src/main/java/com/hazelcast/map/impl/proxy/MapProxySupport.java @@ -138,8 +138,6 @@ abstract class MapProxySupport protected static final String NULL_LISTENER_IS_NOT_ALLOWED = "Null listener is not allowed!"; protected static final String NULL_AGGREGATOR_IS_NOT_ALLOWED = "Aggregator should not be null!"; protected static final String NULL_PROJECTION_IS_NOT_ALLOWED = "Projection should not be null!"; - protected static final String MAX_IDLE_TIME_IS_TOO_SMALL = "Parameter maxIdle in seconds representation must be greater than" - + " or equal to " + MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS; private static final int INITIAL_WAIT_LOAD_SLEEP_MILLIS = 10; private static final int MAXIMAL_WAIT_LOAD_SLEEP_MILLIS = 1000; diff --git a/hazelcast/src/main/java/com/hazelcast/map/impl/recordstore/RecordStore.java b/hazelcast/src/main/java/com/hazelcast/map/impl/recordstore/RecordStore.java index ab3ecdddb942..c4226fea4860 100644 --- a/hazelcast/src/main/java/com/hazelcast/map/impl/recordstore/RecordStore.java +++ b/hazelcast/src/main/java/com/hazelcast/map/impl/recordstore/RecordStore.java @@ -57,11 +57,6 @@ public interface RecordStore { */ long DEFAULT_MAX_IDLE = -1L; - /** - * Minimum non-zero Max Idle value of a record. - */ - long MIN_ALLOWED_MAX_IDLE = 2L; - LocalRecordStoreStats getLocalRecordStoreStats(); String getName(); diff --git a/hazelcast/src/main/java/com/hazelcast/util/Preconditions.java b/hazelcast/src/main/java/com/hazelcast/util/Preconditions.java index 7fac3c5f9f54..a2be5c2a4e8f 100644 --- a/hazelcast/src/main/java/com/hazelcast/util/Preconditions.java +++ b/hazelcast/src/main/java/com/hazelcast/util/Preconditions.java @@ -18,7 +18,6 @@ import java.util.Iterator; import java.util.NoSuchElementException; -import java.util.concurrent.TimeUnit; import static com.hazelcast.internal.partition.InternalPartition.MAX_BACKUP_COUNT; import static java.lang.String.format; @@ -356,21 +355,5 @@ public static void checkState(boolean condition, String message) throws IllegalS throw new IllegalStateException(message); } } - - /** - * Checks if the time is greater or equal than minimum time with respect to their time units. - * @param time the time value - * @param timeUnit the time unit - * @param minTime the minimum time value - * @param minTimeUnit the minimum time value unit - * @param message the error message - * @throws IllegalStateException if the time is less that minimum time - * @throws NullPointerException if {@param leftTimeUnit} or {@param rightTimeUnit} is null - */ - public static void checkMinTimeIfPositive(long time, TimeUnit timeUnit, long minTime, TimeUnit minTimeUnit, String message) { - if (time > 0 && TimeUtil.compare(time, timeUnit, minTime, minTimeUnit) == -1) { - throw new IllegalArgumentException(message); - } - } } diff --git a/hazelcast/src/main/java/com/hazelcast/util/TimeUtil.java b/hazelcast/src/main/java/com/hazelcast/util/TimeUtil.java index 335dca79c1f7..5ac21fb6b08d 100644 --- a/hazelcast/src/main/java/com/hazelcast/util/TimeUtil.java +++ b/hazelcast/src/main/java/com/hazelcast/util/TimeUtil.java @@ -69,20 +69,4 @@ public static long timeInMsOrTimeIfNullUnit(long time, TimeUnit timeUnit) { public static long zeroOutMs(long timestamp) { return SECONDS.toMillis(MILLISECONDS.toSeconds(timestamp)); } - - /** - * Compares two time values that can be present in different time units. - * @param leftTime the first input time value - * @param leftTimeUnit the first input time unit - * @param rightTime the second input time value - * @param rightTimeUnit the second input time unit - * @throws NullPointerException if {@param leftTimeUnit} or {@param rightTimeUnit} is null - * @return -1 if left time is less than right time, 0 if they are equal, - * 1 if left time is greater that right time - */ - public static int compare(long leftTime, TimeUnit leftTimeUnit, long rightTime, TimeUnit rightTimeUnit) { - long leftTimeInMillis = leftTimeUnit.toMillis(leftTime); - long rightTimeInMillis = rightTimeUnit.toMillis(rightTime); - return (leftTimeInMillis < rightTimeInMillis) ? -1 : ((leftTimeInMillis == rightTimeInMillis) ? 0 : 1); - } } diff --git a/hazelcast/src/test/java/com/hazelcast/config/MapConfigTest.java b/hazelcast/src/test/java/com/hazelcast/config/MapConfigTest.java index e1ef2eadb78b..87430e7c8bc3 100644 --- a/hazelcast/src/test/java/com/hazelcast/config/MapConfigTest.java +++ b/hazelcast/src/test/java/com/hazelcast/config/MapConfigTest.java @@ -122,22 +122,6 @@ public void testSetMaxIdleSeconds() { assertEquals(1234, new MapConfig().setMaxIdleSeconds(1234).getMaxIdleSeconds()); } - @Test(expected = IllegalArgumentException.class) - public void testSetMaxIdleSecondsToNegative() { - new MapConfig().setMaxIdleSeconds(-1); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetMaxIdleSecondsToNotAllowed() { - new MapConfig().setMaxIdleSeconds(MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS - 1); - } - - @Test - public void testSetMaxIdleSecondsToDefault() { - assertEquals(MapConfig.DEFAULT_MAX_IDLE_SECONDS, - new MapConfig().setMaxIdleSeconds(MapConfig.DEFAULT_MAX_IDLE_SECONDS).getMaxIdleSeconds()); - } - @Test public void testGetMaxSize() { assertEquals(MaxSizeConfig.DEFAULT_MAX_SIZE, new MapConfig().getMaxSizeConfig().getSize()); diff --git a/hazelcast/src/test/java/com/hazelcast/internal/eviction/MapExpirationBouncingMemberTest.java b/hazelcast/src/test/java/com/hazelcast/internal/eviction/MapExpirationBouncingMemberTest.java index 98d8eaeff607..2e30d59f34d2 100644 --- a/hazelcast/src/test/java/com/hazelcast/internal/eviction/MapExpirationBouncingMemberTest.java +++ b/hazelcast/src/test/java/com/hazelcast/internal/eviction/MapExpirationBouncingMemberTest.java @@ -17,7 +17,6 @@ package com.hazelcast.internal.eviction; import com.hazelcast.config.Config; -import com.hazelcast.config.MapConfig; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.IFunction; import com.hazelcast.core.IMap; @@ -96,7 +95,7 @@ public List apply(HazelcastInstance instance) { protected Config getConfig() { Config config = super.getConfig(); config.getMapConfig(name) - .setMaxIdleSeconds(MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS) + .setMaxIdleSeconds(ONE_SECOND) .setBackupCount(backupCount); return config; } diff --git a/hazelcast/src/test/java/com/hazelcast/map/EvictionTest.java b/hazelcast/src/test/java/com/hazelcast/map/EvictionTest.java index e73b76e31762..f63e13f26ae5 100644 --- a/hazelcast/src/test/java/com/hazelcast/map/EvictionTest.java +++ b/hazelcast/src/test/java/com/hazelcast/map/EvictionTest.java @@ -107,9 +107,9 @@ public void run() throws Exception { public void testMaxIdle_entryShouldNotBeReachableAfterMaxIdle() { final IMap map = createSimpleMap(); - map.put(1, "value0", 0, SECONDS, 2, SECONDS); + map.put(1, "value0", 0, SECONDS, 1, SECONDS); - assertTrueDelayed(2, new AssertTask() { + assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { assertFalse(map.containsKey(1)); @@ -182,7 +182,7 @@ public void testTTL_zeroIsInfinity() { public void testMaxIdle_zeroIsInfinity() { IMap map = createSimpleMap(); - map.put(1, "value0", 0, SECONDS, 2, SECONDS); + map.put(1, "value0", 0, SECONDS, 1, SECONDS); map.put(1, "value1", 0, SECONDS, 0, SECONDS); assertTrue(map.containsKey(1)); @@ -667,7 +667,7 @@ public void run() { @Test public void testMapRecordIdleEviction() { String mapName = randomMapName("testMapRecordIdleEviction"); - int maxIdleSeconds = 2; + int maxIdleSeconds = 1; int size = 100; MapConfig mapConfig = newMapConfig(mapName) @@ -1018,7 +1018,7 @@ private IMap getMapWithExpiredKeys() { @Test @Category(NightlyTest.class) public void testNumberOfEventsFired_withMaxIdleSeconds_whenReadBackupDataEnabled() { - int maxIdleSeconds = 2; + int maxIdleSeconds = 1; int numberOfEntriesToBeAdded = 1000; final AtomicInteger count = new AtomicInteger(0); @@ -1038,7 +1038,7 @@ public void entryEvicted(EntryEvent event) { map.put(i, i); } // wait some time for idle expiration - sleepAtLeastSeconds(3); + sleepAtLeastSeconds(2); for (int i = 0; i < numberOfEntriesToBeAdded; i++) { map.get(i); diff --git a/hazelcast/src/test/java/com/hazelcast/map/MapPreconditionsTest.java b/hazelcast/src/test/java/com/hazelcast/map/MapPreconditionsTest.java index 9343b9a30b8d..0b44e287f6a1 100644 --- a/hazelcast/src/test/java/com/hazelcast/map/MapPreconditionsTest.java +++ b/hazelcast/src/test/java/com/hazelcast/map/MapPreconditionsTest.java @@ -17,7 +17,6 @@ package com.hazelcast.map; import com.hazelcast.config.Config; -import com.hazelcast.config.MapConfig; import com.hazelcast.core.EntryEvent; import com.hazelcast.core.EntryListener; import com.hazelcast.core.HazelcastInstance; @@ -43,7 +42,6 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.TimeUnit; -import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertEquals; @RunWith(HazelcastParallelClassRunner.class) @@ -633,42 +631,6 @@ public Object process(Map.Entry entry) { assertEquals(0, map.size()); } - @Test(expected = IllegalArgumentException.class) - public void testPutAsyncWithNotAllowedMaxIdleTime() { - map.putAsync("key1", "value1", 1, TimeUnit.MINUTES, - MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsyncWithNotAllowedMaxIdleTime() { - map.setAsync("key1", "value1", 1, TimeUnit.MINUTES, - MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testPutWithNotAllowedMaxIdleTime() { - map.put("key1", "value1", 1, TimeUnit.MINUTES, - MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testPutTransientWithNotAllowedMaxIdleTime() { - map.putTransient("key1", "value1", 1, TimeUnit.MINUTES, - MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testPutIfAbsentWithNotAllowedMaxIdleTime() { - map.putIfAbsent("key1", "value1", 1, TimeUnit.MINUTES, - MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS - 1, SECONDS); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetWithNotAllowedMaxIdleTime() { - map.set("key1", "value1", 1, TimeUnit.MINUTES, - MapConfig.MIN_ALLOWED_MAX_IDLE_SECONDS - 1, SECONDS); - } - private class TestEntryListener implements EntryListener { int entryAddedCalled; diff --git a/hazelcast/src/test/java/com/hazelcast/util/PreconditionsTest.java b/hazelcast/src/test/java/com/hazelcast/util/PreconditionsTest.java index 5fd80277d4ca..15fd9378a5dc 100644 --- a/hazelcast/src/test/java/com/hazelcast/util/PreconditionsTest.java +++ b/hazelcast/src/test/java/com/hazelcast/util/PreconditionsTest.java @@ -29,13 +29,11 @@ import java.util.Collections; import java.util.Iterator; import java.util.NoSuchElementException; -import java.util.concurrent.TimeUnit; import static com.hazelcast.internal.partition.InternalPartition.MAX_BACKUP_COUNT; import static com.hazelcast.util.Preconditions.checkFalse; import static com.hazelcast.util.Preconditions.checkHasNext; import static com.hazelcast.util.Preconditions.checkInstanceOf; -import static com.hazelcast.util.Preconditions.checkMinTimeIfPositive; import static com.hazelcast.util.Preconditions.checkNotInstanceOf; import static com.hazelcast.util.Preconditions.checkTrue; import static org.junit.Assert.assertEquals; @@ -369,59 +367,4 @@ public void test_hasNextReturnsIterator_whenNonEmptyIteratorGiven() throws Excep Iterator iterator = Arrays.asList(1, 2).iterator(); assertEquals(iterator, checkHasNext(iterator, "")); } - - @Test - public void testCheckMinTimeIfPositiveTimeIsGreaterSameTimeUnit() { - long time = 3; - TimeUnit timeUnit = TimeUnit.SECONDS; - - long minTime = 2; - TimeUnit minTimeUnit = TimeUnit.SECONDS; - - checkMinTimeIfPositive(time, timeUnit, minTime, minTimeUnit, "valid value"); - } - - @Test - public void testCheckMinTimeIfPositiveTimeIsEqualSameTimeUnit() { - long time = 2; - TimeUnit timeUnit = TimeUnit.SECONDS; - - long minTime = 2; - TimeUnit minTimeUnit = TimeUnit.SECONDS; - - checkMinTimeIfPositive(time, timeUnit, minTime, minTimeUnit, "valid value"); - } - - @Test(expected = IllegalArgumentException.class) - public void testCheckMinTimeIfPositiveTimeIsLessSameTimeUnit() { - long time = 1; - TimeUnit timeUnit = TimeUnit.SECONDS; - - long minTime = 2; - TimeUnit minTimeUnit = TimeUnit.SECONDS; - - checkMinTimeIfPositive(time, timeUnit, minTime, minTimeUnit, "invalid value, time is lower than min value"); - } - - @Test - public void testCheckMinTimeIfPositiveTimeIsZeroSameTimeUnit() { - long time = 0; - TimeUnit timeUnit = TimeUnit.SECONDS; - - long minTime = 2; - TimeUnit minTimeUnit = TimeUnit.SECONDS; - - checkMinTimeIfPositive(time, timeUnit, minTime, minTimeUnit, "valid value"); - } - - @Test - public void testCheckMinTimeIfPositiveTimeIsZeroDifferentTimeUnit() { - long time = 0; - TimeUnit timeUnit = TimeUnit.DAYS; - - long minTime = 2; - TimeUnit minTimeUnit = TimeUnit.SECONDS; - - checkMinTimeIfPositive(time, timeUnit, minTime, minTimeUnit, "valid value"); - } } diff --git a/hazelcast/src/test/java/com/hazelcast/util/TimeUtilTest.java b/hazelcast/src/test/java/com/hazelcast/util/TimeUtilTest.java deleted file mode 100644 index 811aa62850f4..000000000000 --- a/hazelcast/src/test/java/com/hazelcast/util/TimeUtilTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hazelcast.util; - -import com.hazelcast.test.HazelcastParallelClassRunner; -import com.hazelcast.test.HazelcastTestSupport; -import com.hazelcast.test.annotation.ParallelTest; -import com.hazelcast.test.annotation.QuickTest; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; - -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertEquals; - -@RunWith(HazelcastParallelClassRunner.class) -@Category({QuickTest.class, ParallelTest.class}) -public class TimeUtilTest extends HazelcastTestSupport { - - @Test - public void compareLeftTimeIsBeforeSameTimeUnit() { - long leftTime = 2; - TimeUnit leftTimeUnit = TimeUnit.SECONDS; - - long rightTime = 3; - TimeUnit rightTimeUnit = TimeUnit.SECONDS; - - assertEquals(-1, TimeUtil.compare(leftTime, leftTimeUnit, rightTime, rightTimeUnit)); - } - - @Test - public void compareLeftTimeIsBeforeDifferentTimeUnit() { - long leftTime = 2; - TimeUnit leftTimeUnit = TimeUnit.SECONDS; - - long rightTime = 1; - TimeUnit rightTimeUnit = TimeUnit.DAYS; - - assertEquals(-1, TimeUtil.compare(leftTime, leftTimeUnit, rightTime, rightTimeUnit)); - } - - @Test - public void compareLeftTimeIsEqualSameTimeUnit() { - long leftTime = 2; - TimeUnit leftTimeUnit = TimeUnit.SECONDS; - - long rightTime = 2; - TimeUnit rightTimeUnit = TimeUnit.SECONDS; - - assertEquals(0, TimeUtil.compare(leftTime, leftTimeUnit, rightTime, rightTimeUnit)); - } - - @Test - public void compareLeftTimeIsEqualDifferentTimeUnit() { - long leftTime = 60; - TimeUnit leftTimeUnit = TimeUnit.SECONDS; - - long rightTime = 1; - TimeUnit rightTimeUnit = TimeUnit.MINUTES; - - assertEquals(0, TimeUtil.compare(leftTime, leftTimeUnit, rightTime, rightTimeUnit)); - } - - @Test - public void compareLeftTimeIsAfterSameTimeUnit() { - long leftTime = 3; - TimeUnit leftTimeUnit = TimeUnit.SECONDS; - - long rightTime = 2; - TimeUnit rightTimeUnit = TimeUnit.SECONDS; - - assertEquals(1, TimeUtil.compare(leftTime, leftTimeUnit, rightTime, rightTimeUnit)); - } - - @Test - public void compareLeftTimeIsAfterDifferentTimeUnit() { - long leftTime = 61; - TimeUnit leftTimeUnit = TimeUnit.SECONDS; - - long rightTime = 1; - TimeUnit rightTimeUnit = TimeUnit.MINUTES; - - assertEquals(1, TimeUtil.compare(leftTime, leftTimeUnit, rightTime, rightTimeUnit)); - } - - @Test(expected = NullPointerException.class) - public void compareLeftTimeUnitIsNull() { - long leftTime = 61; - TimeUnit leftTimeUnit = null; - - long rightTime = 1; - TimeUnit rightTimeUnit = TimeUnit.MINUTES; - - assertEquals(1, TimeUtil.compare(leftTime, leftTimeUnit, rightTime, rightTimeUnit)); - } - - @Test(expected = NullPointerException.class) - public void compareRightTimeUnitIsNull() { - long leftTime = 61; - TimeUnit leftTimeUnit = TimeUnit.SECONDS; - - long rightTime = 1; - TimeUnit rightTimeUnit = null; - - assertEquals(1, TimeUtil.compare(leftTime, leftTimeUnit, rightTime, rightTimeUnit)); - } -}