Package me.jtalk.accounts.cacher

Source Code of me.jtalk.accounts.cacher.CacherCleanerTest

/*
* Copyright (C) 2014 Roman Nazarenko <me@jtalk.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package me.jtalk.accounts.cacher;

import java.util.concurrent.ConcurrentLinkedQueue;

import me.jtalk.misc.TestTimeSource;

import org.junit.Test;
import static org.junit.Assert.*;

public class CacherCleanerTest {

  public CacherCleanerTest() {
  }

  @Test
  public void testRun() {
    long timeout = Long.MAX_VALUE; // Infinite timeout
    TestTimeSource time = new TestTimeSource();
    ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<>();
    CacherMap<Integer> map = new CacherMap<>(timeout, time);
    CacherCleaner<Integer> cleaner = new CacherCleaner<>(queue, map, time);

    int VALUE_0 = 10;
    int VALUE_1 = 11;
    long TIME_0 = 0;
    long TIME_1 = 10 * 1000;

    time.set(TIME_0);
    queue.add(VALUE_0);
    cleaner.run();

    time.set(TIME_1);
    queue.add(VALUE_1);
    cleaner.run();

    assertEquals(2, map.size());
    assertEquals(TIME_1, map.values().toArray()[1]);
    assertEquals(TIME_0, map.values().toArray()[0]);
    assertEquals(TIME_0, map.get(VALUE_0).longValue());
    assertEquals(TIME_1, map.get(VALUE_1).longValue());
  }

}
TOP

Related Classes of me.jtalk.accounts.cacher.CacherCleanerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.