Exemplo n.º 1
0
  @After
  public void tearDownNeoStore() {
    for (String file :
        new String[] {
          "neo",
          "neo.nodestore.db",
          "neo.nodestore.db.labels",
          "neo.propertystore.db",
          "neo.propertystore.db.index",
          "neo.propertystore.db.index.keys",
          "neo.propertystore.db.strings",
          "neo.propertystore.db.arrays",
          "neo.relationshipstore.db",
          "neo.relationshiptypestore.db",
          "neo.relationshiptypestore.db.names",
          "neo.schemastore.db",
        }) {
      fs.get().deleteFile(file(file));
      fs.get().deleteFile(file(file + ".id"));
    }

    File file = new File(".");
    for (File nioFile : fs.get().listFiles(file)) {
      if (nioFile.getName().startsWith("nioneo_logical.log")) {
        fs.get().deleteFile(nioFile);
      }
    }
  }
Exemplo n.º 2
0
 @Before
 public void setUpNeoStore() throws Exception {
   targetDirectory = TargetDirectory.forTest(fs.get(), getClass());
   path = targetDirectory.directory("dir", true);
   Config config = new Config(new HashMap<String, String>(), GraphDatabaseSettings.class);
   StoreFactory sf =
       new StoreFactory(
           config,
           new DefaultIdGeneratorFactory(),
           new DefaultWindowPoolFactory(),
           fs.get(),
           StringLogger.DEV_NULL,
           null);
   sf.createNeoStore(file(NeoStore.DEFAULT_NAME)).close();
 }
Exemplo n.º 3
0
  private void startDb(KernelExtensionFactory<?> indexProviderFactory) {
    if (db != null) db.shutdown();

    TestGraphDatabaseFactory factory = new TestGraphDatabaseFactory();
    factory.setFileSystem(fs.get());
    factory.setKernelExtensions(Arrays.<KernelExtensionFactory<?>>asList(indexProviderFactory));
    db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
  }
Exemplo n.º 4
0
 @Before
 public void before() throws Exception {
   transactionState = TransactionState.NO_STATE;
   storeFactory =
       new StoreFactory(
           config, idGeneratorFactory, windowPoolFactory, fs.get(), DEV_NULL, new DefaultTxHook());
   neoStore = storeFactory.createNeoStore(new File("neostore"));
   cacheAccessBackDoor = mock(CacheAccessBackDoor.class);
 }
Exemplo n.º 5
0
  /*
   * Starts a JVM, executes a tx that fails on prepare and rollbacks,
   * triggering a bug where an extra start entry for that tx is written
   * in the xa log.
   */
  @Test
  public void testStartEntryWrittenOnceOnRollback() throws Exception {
    final GraphDatabaseService db =
        new TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabase(storeDir);
    createSomeTransactions(db);
    EphemeralFileSystemAbstraction snapshot =
        fs.snapshot(
            new Runnable() {
              @Override
              public void run() {
                db.shutdown();
              }
            });

    new TestGraphDatabaseFactory()
        .setFileSystem(snapshot)
        .newImpermanentDatabase(storeDir)
        .shutdown();
  }
Exemplo n.º 6
0
 private void killDb() {
   if (db != null) {
     fs.snapshot(
         new Runnable() {
           @Override
           public void run() {
             db.shutdown();
             db = null;
           }
         });
   }
 }
Exemplo n.º 7
0
  @Test
  public void twoUncleanInARow() throws Exception {
    String storeDir = new File("dir").getAbsolutePath();
    EphemeralFileSystemAbstraction snapshot = produceUncleanStore(fs.get(), storeDir);
    snapshot = produceUncleanStore(snapshot, storeDir);
    snapshot = produceUncleanStore(snapshot, storeDir);

    GraphDatabaseAPI db =
        (GraphDatabaseAPI)
            new TestGraphDatabaseFactory().setFileSystem(snapshot).newImpermanentDatabase(storeDir);
    assertThat(properties(db), inTx(db, hasProperty("prop").withValue("Some value")));
    db.shutdown();
  }
Exemplo n.º 8
0
  @Test
  public void setVersion() throws Exception {
    String storeDir = "target/test-data/set-version";
    new TestGraphDatabaseFactory()
        .setFileSystem(fs.get())
        .newImpermanentDatabase(storeDir)
        .shutdown();
    assertEquals(1, NeoStore.setVersion(fs.get(), new File(storeDir, NeoStore.DEFAULT_NAME), 10));
    assertEquals(10, NeoStore.setVersion(fs.get(), new File(storeDir, NeoStore.DEFAULT_NAME), 12));

    StoreFactory sf =
        new StoreFactory(
            new Config(new HashMap<String, String>(), GraphDatabaseSettings.class),
            new DefaultIdGeneratorFactory(),
            new DefaultWindowPoolFactory(),
            fs.get(),
            StringLogger.DEV_NULL,
            null);

    NeoStore neoStore = sf.newNeoStore(new File(storeDir, NeoStore.DEFAULT_NAME));
    assertEquals(12, neoStore.getVersion());
    neoStore.close();
  }
Exemplo n.º 9
0
  @Test
  public void firstRecordOtherThanZeroIfNotFirst() throws Exception {
    String storeDir = forTest(getClass()).cleanDirectory("zero").getAbsolutePath();
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(storeDir);
    Transaction tx = db.beginTx();
    Node node = db.createNode();
    node.setProperty("name", "Yo");
    tx.success();
    tx.finish();
    db.shutdown();

    db = (GraphDatabaseAPI) factory.newImpermanentDatabase(storeDir);
    tx = db.beginTx();
    properties(db).setProperty("test", "something");
    tx.success();
    tx.finish();
    db.shutdown();

    Config config =
        configForStoreDir(
            new Config(Collections.<String, String>emptyMap(), GraphDatabaseSettings.class),
            new File(storeDir));
    Monitors monitors = new Monitors();
    StoreFactory storeFactory =
        new StoreFactory(
            config,
            new DefaultIdGeneratorFactory(),
            pageCacheRule.getPageCache(fs.get(), config),
            fs.get(),
            StringLogger.DEV_NULL,
            monitors);
    NeoStore neoStore = storeFactory.newNeoStore(false);
    long prop = neoStore.getGraphNextProp();
    assertTrue(prop != 0);
    neoStore.close();
  }
Exemplo n.º 10
0
 private WriteTransaction newWriteTransaction(
     IndexingService indexing, Visitor<XaCommand, RuntimeException> verifier) {
   log = new VerifyingXaLogicalLog(fs.get(), verifier);
   WriteTransaction result =
       new WriteTransaction(
           0,
           0l,
           log,
           transactionState,
           neoStore,
           cacheAccessBackDoor,
           indexing,
           NO_LABEL_SCAN_STORE,
           new IntegrityValidator(neoStore));
   result.setCommitTxId(neoStore.getLastCommittedTx() + 1);
   return result;
 }
Exemplo n.º 11
0
  @Test
  public void shouldUseConfiguredPageSizeAndFitAsManyPagesAsItCan() throws Exception {
    // Given
    Config config = new Config();
    config.applyChanges(
        stringMap(
            mapped_memory_page_size.name(),
            "4096",
            mapped_memory_total_size.name(),
            Integer.toString(4096 * 16)));

    // When
    PageCacheFactory pageCacheFactory = new StandardPageCacheFactory();
    PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(fsRule.get());
    PageCache cache =
        new LifecycledPageCache(
            pageCacheFactory, swapperFactory, new Neo4jJobScheduler(), config, new Monitors());

    // Then
    assertThat(cache.pageSize(), equalTo(4096));
    assertThat(cache.maxCachedPages(), equalTo(16));
  }
Exemplo n.º 12
0
  @Test
  public void testSetBlockSize() throws Exception {
    targetDirectory.cleanup();

    Config config =
        new Config(
            MapUtil.stringMap("string_block_size", "62", "array_block_size", "302"),
            GraphDatabaseSettings.class);
    StoreFactory sf =
        new StoreFactory(
            config,
            new DefaultIdGeneratorFactory(),
            new DefaultWindowPoolFactory(),
            fs.get(),
            StringLogger.DEV_NULL,
            null);
    sf.createNeoStore(file("neo")).close();

    initializeStores();
    assertEquals(62 + AbstractDynamicStore.BLOCK_HEADER_SIZE, pStore.getStringBlockSize());
    assertEquals(302 + AbstractDynamicStore.BLOCK_HEADER_SIZE, pStore.getArrayBlockSize());
    ds.stop();
  }
Exemplo n.º 13
0
 protected GraphDatabaseAPI newDb() {
   return (GraphDatabaseAPI)
       new TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabase();
 }
Exemplo n.º 14
0
 @Before
 public void before() {
   db =
       (GraphDatabaseAPI)
           new TestGraphDatabaseFactory().setFileSystem(fsRule.get()).newImpermanentDatabase();
 }
Exemplo n.º 15
0
  private void initializeStores() throws IOException {
    LockManager lockManager = new LockManagerImpl(new RagManager());

    final Config config =
        new Config(
            MapUtil.stringMap(
                InternalAbstractGraphDatabase.Configuration.store_dir.name(), path.getPath(),
                InternalAbstractGraphDatabase.Configuration.neo_store.name(), "neo",
                InternalAbstractGraphDatabase.Configuration.logical_log.name(),
                    file("nioneo_logical.log").getPath()),
            GraphDatabaseSettings.class);
    StoreFactory sf =
        new StoreFactory(
            config,
            new DefaultIdGeneratorFactory(),
            new DefaultWindowPoolFactory(),
            fs.get(),
            StringLogger.DEV_NULL,
            null);

    NodeManager nodeManager = mock(NodeManager.class);
    @SuppressWarnings("rawtypes")
    List caches =
        Arrays.asList((Cache) mock(AutoLoadingCache.class), (Cache) mock(AutoLoadingCache.class));
    when(nodeManager.caches()).thenReturn(caches);

    ds =
        new NeoStoreXaDataSource(
            config,
            sf,
            StringLogger.DEV_NULL,
            new XaFactory(
                config,
                TxIdGenerator.DEFAULT,
                new PlaceboTm(lockManager, TxIdGenerator.DEFAULT),
                fs.get(),
                new Monitors(),
                new DevNullLoggingService(),
                RecoveryVerifier.ALWAYS_VALID,
                LogPruneStrategies.NO_PRUNING),
            TransactionStateFactory.noStateFactory(new DevNullLoggingService()),
            new TransactionInterceptorProviders(
                Collections.<TransactionInterceptorProvider>emptyList(),
                dependencyResolverForConfig(config)),
            null,
            new SingleLoggingService(DEV_NULL),
            new KernelSchemaStateStore(),
            mock(TokenNameLookup.class),
            dependencyResolverForNoIndexProvider(nodeManager),
            mock(AbstractTransactionManager.class),
            mock(PropertyKeyTokenHolder.class),
            mock(LabelTokenHolder.class),
            mock(RelationshipTypeTokenHolder.class),
            mock(PersistenceManager.class),
            mock(LockManager.class),
            mock(SchemaWriteGuard.class));
    ds.init();
    ds.start();

    xaCon = ds.getXaConnection();
    pStore = xaCon.getPropertyStore();
    rtStore = xaCon.getRelationshipTypeStore();
  }
Exemplo n.º 16
0
 @Before
 public void before() throws Exception {
   factory = new TestGraphDatabaseFactory().setFileSystem(fs.get());
 }