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();
  }
 @Test
 public void testSetSoftRefCache() {
   ArrayList<CacheProvider> cacheList = new ArrayList<>();
   TestGraphDatabaseFactory gdbf = new TestGraphDatabaseFactory();
   cacheList.add(new SoftCacheProvider());
   gdbf.setCacheProviders(cacheList);
   GraphDatabaseAPI db = (GraphDatabaseAPI) gdbf.newImpermanentDatabase();
   assertEquals(
       SoftCacheProvider.NAME,
       db.getDependencyResolver().resolveDependency(NodeManager.class).getCacheType().getName());
 }
 @Test
 public void testSetNoCache() {
   ArrayList<CacheProvider> cacheList = new ArrayList<>();
   TestGraphDatabaseFactory gdbf = new TestGraphDatabaseFactory();
   gdbf.setCacheProviders(cacheList);
   try {
     gdbf.newImpermanentDatabase();
   } catch (IllegalArgumentException iae) {
     assertTrue(iae.getMessage().contains("No provider for cache type"));
     assertTrue(iae.getMessage().contains("register"));
     assertTrue(iae.getMessage().contains("missing"));
   }
 }
  @Test
  public void basicProperties() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    PropertyContainer graphProperties = properties(db);
    assertThat(graphProperties, inTx(db, not(hasProperty("test"))));

    Transaction tx = db.beginTx();
    graphProperties.setProperty("test", "yo");
    assertEquals("yo", graphProperties.getProperty("test"));
    tx.success();
    tx.finish();
    assertThat(graphProperties, inTx(db, hasProperty("test").withValue("yo")));
    tx = db.beginTx();
    assertNull(graphProperties.removeProperty("something non existent"));
    assertEquals("yo", graphProperties.removeProperty("test"));
    assertNull(graphProperties.getProperty("test", null));
    graphProperties.setProperty("other", 10);
    assertEquals(10, graphProperties.getProperty("other"));
    graphProperties.setProperty("new", "third");
    tx.success();
    tx.finish();
    assertThat(graphProperties, inTx(db, not(hasProperty("test"))));
    assertThat(graphProperties, inTx(db, hasProperty("other").withValue(10)));
    assertThat(getPropertyKeys(db, graphProperties), containsOnly("other", "new"));

    tx = db.beginTx();
    graphProperties.setProperty("rollback", true);
    assertEquals(true, graphProperties.getProperty("rollback"));
    tx.finish();
    assertThat(graphProperties, inTx(db, not(hasProperty("rollback"))));
    db.shutdown();
  }
  @Test
  public void setManyGraphProperties() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();

    Transaction tx = db.beginTx();
    Object[] values =
        new Object[] {
          10,
          "A string value",
          new float[] {1234.567F, 7654.321F},
          "A rather longer string which wouldn't fit inlined #!)(&¤"
        };
    int count = 200;
    for (int i = 0; i < count; i++) {
      properties(db).setProperty("key" + i, values[i % values.length]);
    }
    tx.success();
    tx.finish();

    for (int i = 0; i < count; i++) {
      assertThat(
          properties(db), inTx(db, hasProperty("key" + i).withValue(values[i % values.length])));
    }
    clearCache(db);
    for (int i = 0; i < count; i++) {
      assertThat(
          properties(db), inTx(db, hasProperty("key" + i).withValue(values[i % values.length])));
    }
    db.shutdown();
  }
  @Test
  public void testEquals() {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    PropertyContainer graphProperties = properties(db);
    Transaction tx = db.beginTx();
    try {
      graphProperties.setProperty("test", "test");
      tx.success();
    } finally {
      tx.finish();
    }

    assertEquals(graphProperties, properties(db));
    db.shutdown();
    db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    assertFalse(graphProperties.equals(properties(db)));
    db.shutdown();
  }
  @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();
  }
  @Test
  public void graphPropertiesAreLockedPerTx() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();

    Worker worker1 = new Worker("W1", new State(db));
    Worker worker2 = new Worker("W2", new State(db));

    PropertyContainer properties = properties(db);
    worker1.beginTx();
    worker2.beginTx();

    String key1 = "name";
    String value1 = "Value 1";
    String key2 = "some other property";
    String value2 = "Value 2";
    String key3 = "say";
    String value3 = "hello";
    worker1.setProperty(key1, value1).get();
    assertThat(properties, inTx(db, not(hasProperty(key1))));
    assertFalse(worker2.hasProperty(key1));
    Future<Void> blockedSetProperty = worker2.setProperty(key2, value2);
    assertThat(properties, inTx(db, not(hasProperty(key1))));
    assertThat(properties, inTx(db, not(hasProperty(key2))));
    worker1.setProperty(key3, value3).get();
    assertFalse(blockedSetProperty.isDone());
    assertThat(properties, inTx(db, not(hasProperty(key1))));
    assertThat(properties, inTx(db, not(hasProperty(key2))));
    assertThat(properties, inTx(db, not(hasProperty(key3))));
    worker1.commitTx();
    assertThat(properties, inTx(db, hasProperty(key1)));
    assertThat(properties, inTx(db, not(hasProperty(key2))));
    assertThat(properties, inTx(db, hasProperty(key3)));
    blockedSetProperty.get();
    assertTrue(blockedSetProperty.isDone());
    worker2.commitTx();
    assertThat(properties, inTx(db, hasProperty(key1).withValue(value1)));
    assertThat(properties, inTx(db, hasProperty(key2).withValue(value2)));
    assertThat(properties, inTx(db, hasProperty(key3).withValue(value3)));

    worker1.close();
    worker2.close();
    db.shutdown();
  }
  @Test
  public void setBigArrayGraphProperty() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    long[] array = new long[1000];
    for (int i = 0; i < 10; i++) {
      array[array.length / 10 * i] = i;
    }
    String key = "big long array";
    Transaction tx = db.beginTx();
    properties(db).setProperty(key, array);
    assertThat(properties(db), hasProperty(key).withValue(array));
    tx.success();
    tx.finish();

    assertThat(properties(db), inTx(db, hasProperty(key).withValue(array)));
    clearCache(db);
    assertThat(properties(db), inTx(db, hasProperty(key).withValue(array)));
    db.shutdown();
  }