コード例 #1
0
  @Test
  public void shouldCallDiskDumpForEachRepoAtExit() throws InterruptedException, IOException {
    EntryRepo repoFoo = mock(EntryRepo.class);
    EntryRepo repoBar = mock(EntryRepo.class);
    EntryRepo repoBaz = mock(EntryRepo.class);

    when(repoFoo.isDirty()).thenReturn(true);
    when(repoFoo.diskDump()).thenReturn("foo-data");
    when(repoBar.isDirty()).thenReturn(true);
    when(repoBar.diskDump()).thenReturn("bar-data");
    when(repoBaz.isDirty()).thenReturn(true);
    when(repoBaz.diskDump()).thenReturn("baz-data");

    factory.getRepos().put("foo", repoFoo);
    factory.getRepos().put("bar", repoBar);
    factory.getRepos().put("baz", repoBaz);

    Thread exitHook = factory.exitHook();
    exitHook.start();
    exitHook.join();
    verify(repoFoo).diskDump();
    verify(repoBar).diskDump();
    verify(repoBaz).diskDump();
  }
コード例 #2
0
 @Test
 public void shouldLogExceptionsButContinueDumpingRepositories()
     throws InterruptedException, IOException {
   EntryRepo repoFoo = mock(EntryRepo.class);
   EntryRepo repoBar = mock(EntryRepo.class);
   factory.getRepos().put("foo_subset__size", repoFoo);
   factory.getRepos().put("bar_subset__size", repoBar);
   when(repoFoo.isDirty()).thenReturn(true);
   when(repoFoo.diskDump()).thenThrow(new RuntimeException("test exception"));
   when(repoBar.isDirty()).thenReturn(true);
   when(repoBar.diskDump()).thenReturn("bar-data");
   logFixture.startListening();
   factory.run();
   logFixture.stopListening();
   logFixture.assertHeard("disk dump of foo_subset__size failed");
   verify(repoFoo).diskDump();
   verify(repoBar).diskDump();
 }