コード例 #1
0
  @Test
  public void ifCapacityOrderIsExceeded_thenShouldOverrideLatestEntries() {
    GraphsCache cache = new GraphsCache(2);
    Map<String, Set<String>> graph1 = Collections.singletonMap("a", Collections.singleton("b"));
    Map<String, Set<String>> graph2 = Collections.singletonMap("b", Collections.singleton("c"));
    Map<String, Set<String>> graph3 = Collections.singletonMap("c", Collections.singleton("d"));
    cache.putGraph("x", 1, graph1);
    cache.putGraph("z", 2, graph2);
    cache.putGraph("y", 3, graph3);

    List<Object[]> recent = cache.getRecent();

    assertTuple(recent.get(0), "z", 2);
    assertTuple(recent.get(1), "y", 3);
  }
コード例 #2
0
  @Test
  public void cacheShouldRememberInsertionOrder() {
    Map<String, Set<String>> graph1 = Collections.singletonMap("a", Collections.singleton("b"));
    Map<String, Set<String>> graph2 = Collections.singletonMap("b", Collections.singleton("c"));
    Map<String, Set<String>> graph3 = Collections.singletonMap("c", Collections.singleton("d"));
    cache.putGraph("x", 1, graph1);
    cache.putGraph("z", 2, graph2);
    cache.putGraph("y", 3, graph3);

    List<Object[]> recent = cache.getRecent();

    assertTuple(recent.get(0), "x", 1);
    assertTuple(recent.get(1), "z", 2);
    assertTuple(recent.get(2), "y", 3);
  }