Example #1
0
  @BeforeClass
  @Override
  public void beforeClass() throws Exception {
    super.beforeClass();
    OClass addressClass = database.getMetadata().getSchema().getClass("Address");
    if (addressClass == null) {
      addressClass = database.getMetadata().getSchema().createClass("Address");
    }

    addressClusterId = addressClass.getDefaultClusterId();
  }
Example #2
0
  @Test(enabled = false)
  public void testLiveInsertOnCluster() {
    OLiveCommandExecutorSQLFactory.init();

    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OLiveQueryTest");
    db.activateOnCurrentThread();
    db.create();
    db.registerHook(new OLiveQueryHook(db));
    try {
      OClass clazz = db.getMetadata().getSchema().createClass("test");

      int defaultCluster = clazz.getDefaultClusterId();
      OCluster cluster = db.getStorage().getClusterById(defaultCluster);

      MyLiveQueryListener listener = new MyLiveQueryListener();

      db.query(
          new OLiveQuery<ODocument>("live select from cluster:" + cluster.getName(), listener));

      db.command(
              new OCommandSQL(
                  "insert into cluster:"
                      + cluster.getName()
                      + " set name = 'foo', surname = 'bar'"))
          .execute();

      try {
        Thread.sleep(3000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      Assert.assertEquals(listener.ops.size(), 1);
      for (ORecordOperation doc : listener.ops) {
        Assert.assertEquals(doc.type, ORecordOperation.CREATED);
        Assert.assertEquals(((ODocument) doc.record).field("name"), "foo");
      }
    } finally {
      db.drop();
    }
  }