Ejemplo n.º 1
0
  @Test
  public void shouldSyncReposToDisk() throws ClassNotFoundException, IOException {
    SubsetSizeRepo subsetRepo = factory.createSubsetRepo("dev", LATEST_VERSION);
    SuiteTimeRepo suiteTimeRepo = factory.createSuiteTimeRepo("dev", LATEST_VERSION);
    SuiteResultRepo suiteResultRepo = factory.createSuiteResultRepo("dev", LATEST_VERSION);
    subsetRepo.add(new SubsetSizeEntry(10));
    suiteTimeRepo.update(new SuiteTimeEntry("foo.bar.Quux", 25));
    suiteResultRepo.update(new SuiteResultEntry("foo.bar.Baz", true));

    assertThat(
        "No files should exist as sync on this factory has never been called.",
        baseDir.list().length,
        is(0));

    factory.syncReposToDisk();

    assertThat(
        "Files should exist as sync on this factory has been called.",
        baseDir.list().length,
        is(3));

    assertContentIs(EntryRepoFactory.name("dev", LATEST_VERSION, SUBSET_SIZE), "10");
    assertContentIs(EntryRepoFactory.name("dev", LATEST_VERSION, SUITE_TIME), "foo.bar.Quux: 25");
    assertContentIs(
        EntryRepoFactory.name("dev", LATEST_VERSION, SUITE_RESULT), "foo.bar.Baz: true");
  }
Ejemplo n.º 2
0
 @Test
 public void shouldNotLoadDiskDumpWhenUsingARepoThatIsAlreadyCreated()
     throws ClassNotFoundException, IOException {
   SubsetSizeRepo fooRepo = factory.createSubsetRepo("foo", LATEST_VERSION);
   File file = new File(baseDir, EntryRepoFactory.name("foo", LATEST_VERSION, SUBSET_SIZE));
   ObjectOutputStream outStream = new ObjectOutputStream(new FileOutputStream(file));
   outStream.writeObject(
       new ArrayList<SubsetSizeEntry>(
           Arrays.asList(new SubsetSizeEntry(1), new SubsetSizeEntry(2), new SubsetSizeEntry(3))));
   outStream.close();
   assertThat(fooRepo.list().size(), is(0));
   assertThat(factory.createSubsetRepo("foo", LATEST_VERSION).list().size(), is(0));
 }
Ejemplo n.º 3
0
 @Test
 public void shouldLoadDiskDumpFromStorageRoot() throws IOException, ClassNotFoundException {
   baseDir.mkdirs();
   File file = new File(baseDir, EntryRepoFactory.name("foo", LATEST_VERSION, SUBSET_SIZE));
   FileUtils.writeStringToFile(file, "1\n2\n3\n");
   SubsetSizeRepo repo = factory.createSubsetRepo("foo", LATEST_VERSION);
   assertThat(
       repo.list(),
       is(
           (Collection<SubsetSizeEntry>)
               Arrays.asList(
                   new SubsetSizeEntry(1), new SubsetSizeEntry(2), new SubsetSizeEntry(3))));
 }
Ejemplo n.º 4
0
 @Test
 public void shouldUseWorkingDirAsDiskStorageRootWhenNotGiven()
     throws IOException, ClassNotFoundException {
   final File workingDirStorage = new File(TlbConstants.Server.DEFAULT_TLB_DATA_DIR);
   workingDirStorage.mkdirs();
   File file =
       new File(workingDirStorage, EntryRepoFactory.name("foo", LATEST_VERSION, SUBSET_SIZE));
   FileUtils.writeStringToFile(file, "1\n2\n3\n");
   EntryRepoFactory factory =
       new EntryRepoFactory(new SystemEnvironment(new HashMap<String, String>()));
   SubsetSizeRepo repo = factory.createSubsetRepo("foo", LATEST_VERSION);
   assertThat(
       repo.list(),
       is(
           (Collection<SubsetSizeEntry>)
               Arrays.asList(
                   new SubsetSizeEntry(1), new SubsetSizeEntry(2), new SubsetSizeEntry(3))));
 }
Ejemplo n.º 5
0
  @Test
  public void should_NOT_SyncReposToDisk_unlessDirty() throws ClassNotFoundException, IOException {
    SubsetSizeRepo subsetRepo = factory.createSubsetRepo("dev", LATEST_VERSION);
    SuiteTimeRepo suiteTimeRepo = factory.createSuiteTimeRepo("dev", LATEST_VERSION);
    SuiteResultRepo suiteResultRepo = factory.createSuiteResultRepo("dev", LATEST_VERSION);
    subsetRepo.add(new SubsetSizeEntry(10));
    suiteTimeRepo.update(new SuiteTimeEntry("foo.bar.Quux", 25));
    suiteResultRepo.update(new SuiteResultEntry("foo.bar.Baz", true));

    factory.syncReposToDisk();

    FileUtils.cleanDirectory(baseDir);

    assertThat(baseDir.list().length, is(0));

    factory.syncReposToDisk();

    assertThat(
        "No files should exist as no repos were dirty when sync-to-disk was called.",
        baseDir.list().length,
        is(0));

    subsetRepo.add(new SubsetSizeEntry(21));
    suiteTimeRepo.update(new SuiteTimeEntry("foo.bar.Bang", 35));
    suiteResultRepo.update(new SuiteResultEntry("foo.bar.Baz", true));

    factory.syncReposToDisk();

    assertThat(
        "Files should exist as sync on this factory has been called.",
        baseDir.list().length,
        is(3));

    assertContentIs(EntryRepoFactory.name("dev", LATEST_VERSION, SUBSET_SIZE), "10", "21");
    assertContentIs(
        EntryRepoFactory.name("dev", LATEST_VERSION, SUITE_TIME),
        "foo.bar.Quux: 25",
        "foo.bar.Bang: 35");
    assertContentIs(
        EntryRepoFactory.name("dev", LATEST_VERSION, SUITE_RESULT), "foo.bar.Baz: true");
  }
Ejemplo n.º 6
0
  @Test
  public void shouldBeAbleToLoadFromDumpedFile()
      throws ClassNotFoundException, IOException, InterruptedException {
    SubsetSizeRepo subsetSizeRepo = factory.createSubsetRepo("foo", LATEST_VERSION);
    subsetSizeRepo.add(new SubsetSizeEntry(50));
    subsetSizeRepo.add(new SubsetSizeEntry(100));
    subsetSizeRepo.add(new SubsetSizeEntry(200));

    SuiteTimeRepo subsetTimeRepo = factory.createSuiteTimeRepo("bar", LATEST_VERSION);
    subsetTimeRepo.update(new SuiteTimeEntry("foo.bar.Baz", 10));
    subsetTimeRepo.update(new SuiteTimeEntry("bar.baz.Quux", 20));

    SuiteResultRepo subsetResultRepo = factory.createSuiteResultRepo("baz", LATEST_VERSION);
    subsetResultRepo.update(new SuiteResultEntry("foo.bar.Baz", true));
    subsetResultRepo.update(new SuiteResultEntry("bar.baz.Quux", false));

    Thread exitHook = factory.exitHook();
    exitHook.start();
    exitHook.join();
    EntryRepoFactory otherFactoryInstance = new EntryRepoFactory(env());
    assertThat(
        otherFactoryInstance.createSubsetRepo("foo", LATEST_VERSION).list(),
        is(
            (Collection<SubsetSizeEntry>)
                Arrays.asList(
                    new SubsetSizeEntry(50), new SubsetSizeEntry(100), new SubsetSizeEntry(200))));
    assertThat(
        otherFactoryInstance.createSuiteTimeRepo("bar", LATEST_VERSION).list().size(), is(2));
    assertThat(
        otherFactoryInstance.createSuiteTimeRepo("bar", LATEST_VERSION).list(),
        hasItems(new SuiteTimeEntry("foo.bar.Baz", 10), new SuiteTimeEntry("bar.baz.Quux", 20)));
    assertThat(
        otherFactoryInstance.createSuiteResultRepo("baz", LATEST_VERSION).list().size(), is(2));
    assertThat(
        otherFactoryInstance.createSuiteResultRepo("baz", LATEST_VERSION).list(),
        hasItems(
            new SuiteResultEntry("foo.bar.Baz", true),
            new SuiteResultEntry("bar.baz.Quux", false)));
  }