Exemplo n.º 1
0
 @Test
 public void shouldPurgeDiskDumpAndRepositoryWhenAsked()
     throws IOException, ClassNotFoundException, InterruptedException {
   SuiteTimeRepo fooRepo = factory.createSuiteTimeRepo("foo", LATEST_VERSION);
   fooRepo.update(new SuiteTimeEntry("foo.bar.Baz", 15));
   fooRepo.update(new SuiteTimeEntry("foo.bar.Quux", 80));
   final Thread exitHook = factory.exitHook();
   exitHook.start();
   exitHook.join();
   factory.purge(fooRepo.identifier);
   fooRepo = factory.createSuiteTimeRepo("foo", LATEST_VERSION);
   assertThat(fooRepo.list().size(), is(0));
   fooRepo = new EntryRepoFactory(env()).createSuiteTimeRepo("foo", LATEST_VERSION);
   assertThat(fooRepo.list().size(), is(0));
 }
Exemplo n.º 2
0
  @Test
  public void shouldPurgeDiskDumpAndRepositoryOlderThanGivenTime()
      throws IOException, ClassNotFoundException, InterruptedException {
    final GregorianCalendar[] cal = new GregorianCalendar[1];
    final TimeProvider timeProvider =
        new TimeProvider() {
          @Override
          public GregorianCalendar cal() {
            GregorianCalendar gregorianCalendar = cal[0];
            return gregorianCalendar == null ? null : (GregorianCalendar) gregorianCalendar.clone();
          }

          @Override
          public Date now() {
            return cal().getTime();
          }
        };
    final EntryRepoFactory factory = new EntryRepoFactory(baseDir, timeProvider);

    cal[0] = new GregorianCalendar(2010, 6, 7, 0, 37, 12);

    SuiteTimeRepo repo = factory.createSuiteTimeRepo("foo", LATEST_VERSION);
    repo.update(new SuiteTimeEntry("foo.bar.Baz", 15));
    repo.update(new SuiteTimeEntry("foo.bar.Quux", 80));

    Collection<SuiteTimeEntry> oldList = repo.list("old");
    assertThat(oldList.size(), is(2));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Baz", 15)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));

    repo.update(new SuiteTimeEntry("foo.bar.Bang", 130));
    repo.update(new SuiteTimeEntry("foo.bar.Baz", 20));

    oldList = repo.list("old");
    assertThat(oldList.size(), is(2));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Baz", 15)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));

    cal[0] = new GregorianCalendar(2010, 6, 9, 0, 37, 12);
    Collection<SuiteTimeEntry> notSoOld = repo.list("not_so_old");
    assertThat(notSoOld.size(), is(3));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Baz", 20)));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Bang", 130)));

    repo.update(new SuiteTimeEntry("foo.bar.Foo", 12));

    final Thread exitHook = factory.exitHook();
    exitHook.start();
    exitHook.join();

    cal[0] = new GregorianCalendar(2010, 6, 10, 0, 37, 12);
    factory.purgeVersionsOlderThan(2);

    oldList = repo.list("old");
    assertThat(oldList.size(), is(4));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Baz", 20)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Bang", 130)));
    assertThat(oldList, hasItem(new SuiteTimeEntry("foo.bar.Foo", 12)));

    notSoOld = repo.list("not_so_old");
    assertThat(notSoOld.size(), is(3));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Baz", 20)));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Quux", 80)));
    assertThat(notSoOld, hasItem(new SuiteTimeEntry("foo.bar.Bang", 130)));
  }