Examples of TestTimeSource


Examples of me.jtalk.misc.TestTimeSource

  }

  @Test
  public void testRemoveOneEldestEntry() {
    long timeout = 20;
    TestTimeSource time = new TestTimeSource();
    CacherMap<Integer> map = new CacherMap<>(timeout, time);

    time.set(0); // All are new right now

    int KEY_OLD = 1;
    int KEY_NEW_1 = 2;
    int KEY_NEW_2 = 3;

    map.put(KEY_OLD, (long)9 * 1000);
    map.put(KEY_NEW_1, (long)30 * 1000);

    time.set(30 * 1000);

    map.put(KEY_NEW_2, (long)31 * 1000);

    assertEquals(2, map.size());
    assertTrue(map.containsKey(KEY_NEW_1));
View Full Code Here

Examples of me.jtalk.misc.TestTimeSource

  }

  @Test
  public void testRemoveEldestEntryAll() {
    long timeout = 20;
    TestTimeSource time = new TestTimeSource();
    CacherMap<Integer> map = new CacherMap<>(timeout, time);

    time.set(0); // All are new right now

    int KEY_OLD_1 = 1;
    int KEY_OLD_2 = 2;
    int KEY_OLD_3 = 3;

    map.put(KEY_OLD_1, (long)10);
    map.put(KEY_OLD_2, (long)11);

    time.set(33);
    map.put(KEY_OLD_3, (long)12);

    assertTrue(map.isEmpty());
  }
View Full Code Here

Examples of me.jtalk.misc.TestTimeSource

  }

  @Test
  public void testRemoveZeroEldestEntries() {
    long timeout = Long.MAX_VALUE;
    TestTimeSource time = new TestTimeSource();
    CacherMap<Integer> map = new CacherMap<>(timeout, time);

    time.set(31); // All are new right now

    int KEY_NEW_1 = 1;
    int KEY_NEW_2 = 2;
    int KEY_NEW_3 = 3;
View Full Code Here

Examples of me.jtalk.misc.TestTimeSource

  }

  @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]);
View Full Code Here
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.