@Test
  public void shouldHaltUpgradeIfUpgradeConfigurationVetoesTheProcess() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldHaltUpgradeIfUpgradeConfigurationVetoesTheProcess");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    UpgradeConfiguration vetoingUpgradeConfiguration =
        new UpgradeConfiguration() {
          public void checkConfigurationAllowsAutomaticUpgrade() {
            throw new UpgradeNotAllowedByConfigurationException("vetoed");
          }
        };

    try {
      newUpgrader(
              vetoingUpgradeConfiguration,
              new StoreMigrator(new SilentMigrationProgressMonitor()),
              new DatabaseFiles())
          .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());
      fail("Should throw exception");
    } catch (UpgradeNotAllowedByConfigurationException e) {
      // expected
    }
  }
  @Test
  public void shouldRefuseToUpgradeIfAllOfTheStoresWeNotShutDownCleanly() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldRefuseToUpgradeIfAllOfTheStoresWeNotShutDownCleanly");
    File comparisonDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldRefuseToUpgradeIfAllOfTheStoresWeNotShutDownCleanly-comparison");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    truncateAllFiles(workingDirectory);
    deleteRecursively(comparisonDirectory);
    copyRecursively(workingDirectory, comparisonDirectory);

    try {
      newUpgrader(
              alwaysAllowed(),
              new StoreMigrator(new SilentMigrationProgressMonitor()),
              new DatabaseFiles())
          .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());
      fail("Should throw exception");
    } catch (StoreUpgrader.UnableToUpgradeException e) {
      // expected
    }

    verifyFilesHaveSameContent(comparisonDirectory, workingDirectory);
  }
  @Test
  public void shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound");
    File comparisonDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound-comparison");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    changeVersionNumber(new File(workingDirectory, "neostore.nodestore.db"), "v0.9.5");
    deleteRecursively(comparisonDirectory);
    copyRecursively(workingDirectory, comparisonDirectory);

    try {
      newUpgrader(
              alwaysAllowed(),
              new StoreMigrator(new SilentMigrationProgressMonitor()),
              new DatabaseFiles())
          .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());
      fail("Should throw exception");
    } catch (StoreUpgrader.UnableToUpgradeException e) {
      // expected
    }

    verifyFilesHaveSameContent(comparisonDirectory, workingDirectory);
  }
  @Test
  public void shouldLeaveACopyOfOriginalStoreFilesInBackupDirectory() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldLeaveACopyOfOriginalStoreFilesInBackupDirectory");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    newUpgrader(
            alwaysAllowed(),
            new StoreMigrator(new SilentMigrationProgressMonitor()),
            new DatabaseFiles())
        .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());

    verifyFilesHaveSameContent(
        MigrationTestUtils.findOldFormatStoreDirectory(),
        new File(workingDirectory, "upgrade_backup"));
  }
Esempio n. 5
0
 @Before
 public void setUp() {
   Config config = StoreFactory.configForStoreDir(MigrationTestUtils.defaultConfig(), storeDir);
   Monitors monitors = new Monitors();
   storeFactory =
       new StoreFactory(
           config,
           new DefaultIdGeneratorFactory(),
           pageCacheRule.getPageCache(fs, config),
           fs,
           StringLogger.DEV_NULL,
           monitors);
 }
  @Test
  public void shouldUpgradeAnOldFormatStore() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldUpgradeAnOldFormatStore");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    assertTrue(allStoreFilesHaveVersion(workingDirectory, "v0.9.9"));

    newUpgrader(
            alwaysAllowed(),
            new StoreMigrator(new SilentMigrationProgressMonitor()),
            new DatabaseFiles())
        .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());

    assertTrue(allStoreFilesHaveVersion(workingDirectory, ALL_STORES_VERSION));
  }
Esempio n. 7
0
  @Test
  public void shouldReadAnArrayPropertyRecordById() throws IOException {
    URL propertyStoreFile = getClass().getResource("exampledb/neostore.propertystore.db");
    URL stringStoreFile = getClass().getResource("exampledb/neostore.propertystore.db.strings");
    URL arrayStoreFile = getClass().getResource("exampledb/neostore.propertystore.db.arrays");

    LegacyPropertyRecord propertyRecord2 =
        new LegacyPropertyStoreReader(new File(propertyStoreFile.getFile())).readPropertyRecord(32);

    int keyIndexId = propertyRecord2.getKeyIndexId();
    assertEquals(10, keyIndexId);
    Object value =
        propertyRecord2
            .getType()
            .getValue(
                propertyRecord2,
                new LegacyDynamicRecordFetcher(
                    new File(stringStoreFile.getFile()), new File(arrayStoreFile.getFile())));
    assertArrayEquals(MigrationTestUtils.makeLongArray(), (int[]) value);
  }
 @Before
 public void prepareDirectory() throws IOException {
   workingDirectory = MigrationTestUtils.findOldFormatStoreDirectory();
 }