/*
 * 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.map.impl.eviction;

import com.hazelcast.config.Config;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.MaxSizeConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
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.assertNotNull;
import static org.junit.Assert.assertNull;

@RunWith(HazelcastParallelClassRunner.class)
@Category({QuickTest.class, ParallelTest.class})
public class ExpirationManagerTimeoutTest extends HazelcastTestSupport {

    @Test
    public void afterShortExpirationEntryShouldBeAway() throws InterruptedException {
        final String KEY = "key";

        Config hConfig = new Config()
                .addMapConfig(new MapConfig().setName("test")
                        .setMaxSizeConfig(new MaxSizeConfig(200, MaxSizeConfig.MaxSizePolicy.FREE_HEAP_SIZE))
                        .setTimeToLiveSeconds(20));
        final HazelcastInstance node = createHazelcastInstance(hConfig);
        try {
            IMap<String, String> map = node.getMap("test");
            // after 1 second entry should be evicted
            map.put(KEY, "value", 1, TimeUnit.SECONDS);
            // short time after adding it to the map, all ok
            map.lock(KEY);
            Object object = map.get(KEY);
            map.unlock(KEY);
            assertNotNull(object);

            Thread.sleep(1200);

            // more than one second after adding it, now it should be away
            map.lock(KEY);
            object = map.get(KEY);
            map.unlock(KEY);
            assertNull(object);
        } finally {
            node.shutdown();
        }
    }

    @Test
    public void afterLongerExpirationEntryShouldBeAway() throws InterruptedException {
        final String KEY = "key";

        Config hConfig = new Config()
                .addMapConfig(new MapConfig().setName("test")
                        .setMaxSizeConfig(new MaxSizeConfig(200, MaxSizeConfig.MaxSizePolicy.FREE_HEAP_SIZE))
                        .setTimeToLiveSeconds(20));
        final HazelcastInstance node = createHazelcastInstance(hConfig);
        try {
            IMap<String, String> map = node.getMap("test");
            // after 1 second entry should be evicted
            map.put(KEY, "value", 1, TimeUnit.SECONDS);
            // short time after adding it to the map, all ok
            map.lock(KEY);
            Object object = map.get(KEY);
            map.unlock(KEY);
            assertNotNull(object);
            Thread.sleep(3600);
            // More than one second after adding it, now it should be away
            map.lock(KEY);
            object = map.get(KEY);
            map.unlock(KEY);
            assertNull(object);
        } finally {
            node.shutdown();
        }
    }
}

@@ -666,126 +666,8 @@
 n;%0A%0A
-import com.hazelcast.config.Config;%0Aimport com.hazelcast.config.MapConfig;%0Aimport com.hazelcast.config.MaxSizeConfig;%0A
 impo
@@ -1482,270 +1482,8 @@
 %22;%0A%0A
-        Config hConfig = new Config()%0A                .addMapConfig(new MapConfig().setName(%22test%22)%0A                        .setMaxSizeConfig(new MaxSizeConfig(200, MaxSizeConfig.MaxSizePolicy.FREE_HEAP_SIZE))%0A                        .setTimeToLiveSeconds(20));%0A
     
@@ -1533,39 +1533,32 @@
 zelcastInstance(
-hConfig
 );%0A        try %7B
@@ -1680,34 +1680,34 @@
             map.
-pu
+se
 t(KEY, %22value%22, 
@@ -1699,32 +1699,35 @@
 (KEY, %22value%22, 1
+500
 , TimeUnit.SECON
@@ -1713,32 +1713,37 @@
  1500, TimeUnit.
+MILLI
 SECONDS);%0A      
@@ -1947,23 +1947,29 @@
     
-Thread.sleep(12
+sleepAtLeastMillis(17
 00);
@@ -2370,270 +2370,8 @@
 %22;%0A%0A
-        Config hConfig = new Config()%0A                .addMapConfig(new MapConfig().setName(%22test%22)%0A                        .setMaxSizeConfig(new MaxSizeConfig(200, MaxSizeConfig.MaxSizePolicy.FREE_HEAP_SIZE))%0A                        .setTimeToLiveSeconds(20));%0A
     
@@ -2433,15 +2433,8 @@
 nce(
-hConfig
 );%0A 
@@ -2519,33 +2519,33 @@
        // after 
-1
+3
  second entry sh
@@ -2576,18 +2576,18 @@
     map.
-pu
+se
 t(KEY, %22
@@ -2594,17 +2594,17 @@
 value%22, 
-1
+3
 , TimeUn
@@ -2802,32 +2802,33 @@
 otNull(object);%0A
+%0A
             Thre
@@ -2827,28 +2827,34 @@
     
-Thread.sleep
+sleepAtLeastMillis
 (3600);%0A
     
@@ -2849,16 +2849,17 @@
 (3600);%0A
+%0A
         
@@ -2871,34 +2871,33 @@
 / More than 
-one
+3
  second
+s
  after addin

Remove eviction configuration and re-adjust expiry timeouts (#15094)