示例#1
0
  /**
   * Verifies that a list of three non-nested transactions all persist correctly.
   *
   * @throws Exception
   */
  public void testPersistTransactions() throws Exception {
    AnzoClient client1 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    // client.setNotificationEnabled(false);
    try {
      client1.clear();

      client1.begin();
      ClientGraph replicaGraph = client1.getReplicaGraph(TestData.graph2);
      replicaGraph.add(TestData.stmt2);
      client1.commit();

      client1.begin();
      replicaGraph.add(TestData.stmt3);
      client1.commit();

      client1.begin();
      replicaGraph.add(TestData.stmt4);
      client1.commit();
    } finally {
      client1.close();
    }

    AnzoClient client2 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    try {
      assertEquals(3, client2.transactionQueue.committedTransactions.size());

      ClientGraph graph = client2.getReplicaGraph(TestData.graph2);
      assertTrue(graph.contains(TestData.stmt2));
      assertTrue(graph.contains(TestData.stmt3));
      assertTrue(graph.contains(TestData.stmt4));
    } finally {
      client2.close();
    }
  }
示例#2
0
  /**
   * Make sure an exception is thrown if an attempt is made to create more than one client that uses
   * the same container name, meaning they would be using the persistent database tables, which is
   * not allowed.
   *
   * @throws Exception
   */
  public void testIllegalSharedDatabase() throws Exception {
    AnzoClient client1 = null;
    AnzoClient client2 = null;
    try {
      AnzoException exception = null;
      try {
        Properties properties = TestUtilities.getProperties();
        AnzoClientProperties.setPersistenceEnabled(properties, true);
        client1 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
        client2 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());

      } catch (AnzoException e) {
        exception = e;
      }
      assertNotNull(exception);
    } finally {
      if (client1 != null) client1.close();
      if (client2 != null) client2.close();
    }
  }
示例#3
0
  /**
   * Verifies that replicated Quads are persisted correctly.
   *
   * <p>See also testPersistTransaction, which verifies Quads that have not been replicated (and are
   * in the transaction queue) are persisted correctly.
   *
   * @throws Exception
   */
  public void testPersistQuad() throws Exception {
    AnzoClient client1 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    // client.setNotificationEnabled(false);
    try {
      client1.clear();

      ClientGraph graph = client1.getReplicaGraph(TestData.graph1);
      graph.add(TestData.stmt1);
      client1.quadStore.add(TestData.stmt1);
    } finally {
      client1.close();
    }
    AnzoClient client2 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    // client2.setNotificationEnabled(false);
    try {
      ClientGraph graph = client2.getReplicaGraph(TestData.graph1);
      assertTrue(graph.contains(TestData.stmt1));
    } finally {
      client2.close();
    }
  }
示例#4
0
  /**
   * Verifies that all the fields of a precondition are persisted correctly.
   *
   * @throws Exception
   */
  public void testPersistPrecondition() throws Exception {
    String preconditionQuery = "ASK WHERE (?s ?p ?o)";

    AnzoClient client1 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    // client.setNotificationEnabled(false);
    try {
      client1.clear();
      Precondition precondition =
          new Precondition(
              Collections.singleton(TestData.graph1),
              Collections.singleton(TestData.graph2),
              preconditionQuery,
              true);

      client1.begin(Collections.<IPrecondition>singleton(precondition));
      ClientGraph replicaGraph = client1.getReplicaGraph(TestData.graph2);
      replicaGraph.add(TestData.stmt2);
      client1.commit();
    } finally {
      client1.close();
    }
    AnzoClient client2 = new AnzoClient(TestConfiguration.getPersistenceConfiguration());
    try {
      Transaction transaction = client2.transactionQueue.committedTransactions.get(0);
      Set<IPrecondition> preconditions = transaction.preconditions;
      assertNotNull(preconditions);
      Iterator<IPrecondition> iterator = preconditions.iterator();
      assertTrue(iterator.hasNext());
      IPrecondition next = iterator.next();

      assertEquals(preconditionQuery, next.getQuery());
      assertTrue(next.getDefaultGraphUris().contains(TestData.graph1));
      assertTrue(next.getNamedGraphUris().contains(TestData.graph2));
      AskResult result = (AskResult) next.getResult();
      assertTrue(result.getResultValue());
    } finally {
      client2.close();
    }
  }