@Test
 public void shouldBeAbleToTraverseEverything() {
   long startNode = createBasicTraversableGraph();
   List<Object> hits =
       serialize(
           actions.traverse(
               startNode,
               MapUtil.map(
                   "return_filter",
                   MapUtil.map("language", "javascript", "body", "true;"),
                   "max_depth",
                   10),
               TraverserReturnType.node));
   assertEquals(6, hits.size());
   hits =
       serialize(
           actions.traverse(
               startNode,
               MapUtil.map(
                   "return_filter",
                   MapUtil.map("language", "builtin", "name", "all"),
                   "max_depth",
                   10),
               TraverserReturnType.node));
   assertEquals(6, hits.size());
 }
 @Test
 public void shouldBeAbleToTraverseWithMaxDepthAndPruneEvaluatorCombined() {
   long startNode = createBasicTraversableGraph();
   List<Object> hits =
       serialize(
           actions.traverse(
               startNode,
               MapUtil.map(
                   "max_depth",
                   2,
                   "prune_evaluator",
                   MapUtil.map(
                       "language",
                       "javascript",
                       "body",
                       "position.endNode().getProperty('name').equals('Emil')")),
               TraverserReturnType.node));
   assertEquals(3, hits.size());
   hits =
       serialize(
           actions.traverse(
               startNode,
               MapUtil.map(
                   "max_depth",
                   1,
                   "prune_evaluator",
                   MapUtil.map(
                       "language",
                       "javascript",
                       "body",
                       "position.endNode().getProperty('name').equals('Emil')")),
               TraverserReturnType.node));
   assertEquals(2, hits.size());
 }
  public void importa(BatchInserter inserter, LuceneBatchInserterIndexProvider indexProvider) {

    BatchInserterIndex pessoas =
        indexProvider.nodeIndex("pessoas", MapUtil.stringMap("type", "fulltext"));

    Scanner sc = new Scanner(ImportadorPessoas.class.getResourceAsStream("/import/pessoas"));

    System.out.println("Início da importação das pessoas");
    while (sc.hasNextLine()) {
      String linha = sc.nextLine();
      String[] informacoesDePessoa = linha.split(";");
      long id = Long.parseLong(informacoesDePessoa[0]);
      String nome = informacoesDePessoa[1];
      Integer idade = Integer.parseInt(informacoesDePessoa[2]);

      Map<String, Object> propriedades = MapUtil.map("nome", nome, "idade", idade);

      inserter.createNode(id, propriedades);
      pessoas.add(id, MapUtil.map("nome", nome));
      inserter.createRelationship(0, id, Relacionamentos.PESSOA, null);
    }

    pessoas.flush();

    System.out.println("Fim da importação das pessoas");
  }
 @Test
 public void testConvertMapToMapWithSameType() {
   Object result =
       converter.convertToResultType(
           MapUtil.map("test", 1, "test2", 2), new TypeInformation(MapUtil.map("test", 0)));
   assertEquals(MapUtil.map("test", 1, "test2", 2), result);
 }
  @Override
  public void generate(String dbPath) {
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase(dbPath);
    Index<Node> nodeIndex =
        graphDb
            .index()
            .forNodes("nodes", MapUtil.stringMap("provider", "lucene", "type", "fulltext"));
    Index<Relationship> relationshipIndex =
        graphDb
            .index()
            .forRelationships(
                "relationships", MapUtil.stringMap("provider", "lucene", "type", "fulltext"));
    Transaction tx = graphDb.beginTx();
    try {
      Node n = graphDb.createNode();
      Node n2 = graphDb.createNode();
      Relationship rel = n.createRelationshipTo(n2, REL_TYPE);

      nodeIndex.add(n, "name", "alpha bravo");
      nodeIndex.add(n2, "name", "charlie delta");
      relationshipIndex.add(rel, "name", "echo foxtrot");

      tx.success();
    } finally {
      tx.finish();
    }
    graphDb.shutdown();
  }
Example #6
0
  public void importFromFile(String filePath) throws IOException {
    Map<String, Long> cache = new HashMap<String, Long>(COUNT);
    final File storeDir = new File(this.path);
    org.apache.commons.io.FileUtils.deleteDirectory(storeDir);
    BatchInserter batchInserter = new BatchInserterImpl(storeDir.getAbsolutePath());
    final BatchInserterIndexProvider indexProvider =
        new LuceneBatchInserterIndexProvider(batchInserter);
    final BatchInserterIndex index =
        indexProvider.nodeIndex("nodes", MapUtil.stringMap("type", "exact"));
    BufferedReader reader = new BufferedReader(new FileReader(filePath));
    String line = null;
    int nodes = 0;
    long time = System.currentTimeMillis();
    long batchTime = time;
    while ((line = reader.readLine()) != null) {
      final String[] nodeNames = line.split("\\|");
      final String name = nodeNames[0];
      final Map<String, Object> props = MapUtil.map("name", name);
      final long node = batchInserter.createNode(props);
      index.add(node, props);
      cache.put(name, node);
      nodes++;
      if ((nodes % REPORT_COUNT) == 0) {
        System.out.printf(
            "%d nodes created. Took %d %n", nodes, (System.currentTimeMillis() - batchTime));
        batchTime = System.currentTimeMillis();
      }
    }

    System.out.println("Creating nodes took " + (System.currentTimeMillis() - time) / 1000);
    index.flush();
    reader.close();
    reader = new BufferedReader(new FileReader(filePath));
    int rels = 0;
    time = System.currentTimeMillis();
    batchTime = time;
    String relationshipType = "KNOWS";
    while ((line = reader.readLine()) != null) {
      final String[] nodeNames = line.split("\\|");
      final String name = nodeNames[0];
      // final Long from = index.get("name", name).getSingle();
      Long from = cache.get(name);
      for (int j = 1; j < nodeNames.length; j++) {
        // final Long to = index.get("name", nodeNames[j]).getSingle();
        final Long to = cache.get(name);
        batchInserter.createRelationship(
            from, to, DynamicRelationshipType.withName(relationshipType), null);
      }
      rels++;
      if ((rels % REPORT_COUNT) == 0) {
        System.out.printf(
            "%d relationships created. Took %d %n", rels, (System.currentTimeMillis() - batchTime));
        batchTime = System.currentTimeMillis();
      }
    }
    System.out.println("Creating relationships took " + (System.currentTimeMillis() - time) / 1000);
    indexProvider.shutdown();
    batchInserter.shutdown();
  }
 @Test
 public void testConvertDifferentMapsWithSameType() {
   Hashtable<String, String> table = new Hashtable<String, String>();
   table.put("testkey", "testvalue");
   Object result =
       converter.convertToResultType(table, new TypeInformation(MapUtil.map("test", "test")));
   assertEquals(MapUtil.map("testkey", "testvalue"), result);
 }
 @Test
 public void testConvertJSONDataToRelationship() {
   Object result =
       converter.convertToResultType(
           MapUtil.map(
               "self",
               "http://localhost:7474/db/data/relationship/2",
               "data",
               MapUtil.map("propname", "testprop")),
           new TypeInformation(RestRelationship.class));
   assertEquals(RestRelationship.class, result.getClass());
   assertEquals("testprop", ((Relationship) result).getProperty("propname"));
 }
  @Test
  public void shouldSendAMessageFromAClientWhichIsReceivedByAServer() throws Exception {

    // given

    CountDownLatch latch = new CountDownLatch(1);

    LifeSupport life = new LifeSupport();

    Server server1 =
        new Server(
            latch,
            MapUtil.stringMap(
                ClusterSettings.cluster_server.name(),
                "localhost:1234",
                ClusterSettings.server_id.name(),
                "1",
                ClusterSettings.initial_hosts.name(),
                "localhost:1234,localhost:1235"));

    life.add(server1);

    Server server2 =
        new Server(
            latch,
            MapUtil.stringMap(
                ClusterSettings.cluster_server.name(),
                "localhost:1235",
                ClusterSettings.server_id.name(),
                "2",
                ClusterSettings.initial_hosts.name(),
                "localhost:1234,localhost:1235"));

    life.add(server2);

    life.start();

    // when

    server1.process(
        Message.to(TestMessage.helloWorld, URI.create("cluster://127.0.0.1:1235"), "Hello World"));

    // then

    latch.await(5, TimeUnit.SECONDS);

    assertTrue("server1 should have processed the message", server1.processedMessage());
    assertTrue("server2 should have processed the message", server2.processedMessage());

    life.shutdown();
  }
 @Before
 public void before() throws Exception {
   dir = TargetDirectory.forTest(getClass()).directory("db", true);
   Map<String, String> configParams = MapUtil.stringMap();
   Config config = new Config(configParams);
   DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory();
   DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();
   StoreFactory factory =
       new StoreFactory(
           config,
           idGeneratorFactory,
           new DefaultWindowPoolFactory(),
           fs,
           StringLogger.DEV_NULL,
           new DefaultTxHook());
   String fileName = new File(dir, "arraystore").getAbsolutePath();
   factory.createDynamicArrayStore(fileName, 120);
   arrayStore =
       new DynamicArrayStore(
           fileName,
           config,
           IdType.ARRAY_BLOCK,
           idGeneratorFactory,
           new DefaultWindowPoolFactory(),
           fs,
           StringLogger.DEV_NULL);
 }
  private MasterTxIdGenerator newGenerator(
      int slaveCount, int replication, SlavePriority slavePriority, boolean... failingSlaves)
      throws Exception {
    slaves = instantiateSlaves(slaveCount, failingSlaves);
    dataSource = new FakeDataSource();

    log = new FakeStringLogger();
    Config config =
        new Config(MapUtil.stringMap(HaSettings.tx_push_factor.name(), "" + replication));
    Neo4jJobScheduler scheduler = new Neo4jJobScheduler();
    MasterTxIdGenerator result =
        new MasterTxIdGenerator(
            MasterTxIdGenerator.from(config, slavePriority),
            log,
            new Slaves() {
              @Override
              public Iterable<Slave> getSlaves() {
                return slaves;
              }
            },
            new CommitPusher(scheduler));
    // Life
    try {
      scheduler.init();
      scheduler.start();

      result.init();
      result.start();
    } catch (Throwable e) {
      throw Exceptions.launderedException(e);
    }
    return result;
  }
Example #12
0
  /** Remove all entries with a given node, key and value from an index. */
  @Documented
  @Test
  public void shouldBeAbleToRemoveIndexingByIdAndKeyAndValue() {
    String key1 = "kvkey1";
    String key2 = "kvkey2";
    String value1 = "value1";
    String value2 = "value2";
    String indexName = "kvnode";
    long node =
        helper.createNode(MapUtil.map(key1, value1, key1, value2, key2, value1, key2, value2));
    helper.addNodeToIndex(indexName, key1, value1, node);
    helper.addNodeToIndex(indexName, key1, value2, node);
    helper.addNodeToIndex(indexName, key2, value1, node);
    helper.addNodeToIndex(indexName, key2, value2, node);

    gen()
        .noGraph()
        .expectedStatus(204)
        .delete(
            functionalTestHelper.nodeIndexUri()
                + indexName
                + "/"
                + key1
                + "/"
                + value1
                + "/"
                + node);

    assertEquals(0, helper.getIndexedNodes(indexName, key1, value1).size());
    assertEquals(1, helper.getIndexedNodes(indexName, key1, value2).size());
    assertEquals(1, helper.getIndexedNodes(indexName, key2, value1).size());
    assertEquals(1, helper.getIndexedNodes(indexName, key2, value2).size());
  }
 @Test
 public void testUdcPropertyFileKeysMatchSettings() throws Exception {
   Map<String, String> config =
       MapUtil.load(getClass().getResourceAsStream("/org/neo4j/ext/udc/udc.properties"));
   assertEquals("test-reg", config.get(UdcSettings.udc_registration_key.name()));
   assertEquals("unit-testing", config.get(UdcSettings.udc_source.name()));
 }
 @Test
 public void shouldBeAbleToTraverseDepthTwo() {
   long startNode = createBasicTraversableGraph();
   List<Object> hits =
       serialize(
           actions.traverse(startNode, MapUtil.map("max_depth", 2), TraverserReturnType.node));
   assertEquals(3, hits.size());
 }
Example #15
0
    private void startMember(int serverId) throws URISyntaxException {
      Clusters.Member member = spec.getMembers().get(serverId - 1);
      StringBuilder initialHosts = new StringBuilder(spec.getMembers().get(0).getHost());
      for (int i = 1; i < spec.getMembers().size(); i++)
        initialHosts.append(",").append(spec.getMembers().get(i).getHost());
      if (member.isFullHaMember()) {
        int haPort = new URI("cluster://" + member.getHost()).getPort() + 3000;
        GraphDatabaseBuilder graphDatabaseBuilder =
            new HighlyAvailableGraphDatabaseFactory()
                .newHighlyAvailableDatabaseBuilder(
                    new File(new File(root, name), "server" + serverId).getAbsolutePath())
                .setConfig(ClusterSettings.cluster_name, name)
                .setConfig(ClusterSettings.initial_hosts, initialHosts.toString())
                .setConfig(HaSettings.server_id, serverId + "")
                .setConfig(ClusterSettings.cluster_server, member.getHost())
                .setConfig(HaSettings.ha_server, ":" + haPort)
                .setConfig(commonConfig);
        if (instanceConfig.containsKey(serverId)) {
          graphDatabaseBuilder.setConfig(instanceConfig.get(serverId));
        }

        config(graphDatabaseBuilder, name, serverId);

        logger.info("Starting cluster node " + serverId + " in cluster " + name);
        final GraphDatabaseService graphDatabase = graphDatabaseBuilder.newGraphDatabase();

        members.put(serverId, (HighlyAvailableGraphDatabase) graphDatabase);

        life.add(
            new LifecycleAdapter() {
              @Override
              public void stop() throws Throwable {
                graphDatabase.shutdown();
              }
            });
      } else {
        Map<String, String> config =
            MapUtil.stringMap(
                ClusterSettings.cluster_name.name(), name,
                ClusterSettings.initial_hosts.name(), initialHosts.toString(),
                ClusterSettings.cluster_server.name(), member.getHost());
        Logging clientLogging =
            new Logging() {
              @Override
              public StringLogger getLogger(Class loggingClass) {
                return new Slf4jStringLogger(logger);
              }
            };
        life.add(
            new ClusterClient(
                ClusterClient.adapt(new Config(config)),
                clientLogging,
                new CoordinatorIncapableCredentialsProvider()));
      }

      // logger.info( "Started cluster node " + serverId + " in cluster "
      // + name );
    }
Example #16
0
  private static void initializeIndex() {
    indexProvider = new LuceneBatchInserterIndexProvider(inserter);
    nodeIndex = indexProvider.nodeIndex("nodeIndex", MapUtil.stringMap("type", "exact"));

    // TODO: Does this have an effect at all?
    nodeIndex.setCacheCapacity(NodeKeys.TYPE, 100000);
    nodeIndex.setCacheCapacity(NodeKeys.NAME, 100000);
    nodeIndex.setCacheCapacity(NodeKeys.CODE, 100000);
  }
 @Override
 public <T> void addToIndex(T entity, RestIndex index, String key, Object value) {
   final RestEntity restEntity = (RestEntity) entity;
   String uri = restEntity.getUri();
   if (value instanceof ValueContext) {
     value = ((ValueContext) value).getCorrectValue();
   }
   final Map<String, Object> data = MapUtil.map("key", key, "value", value, "uri", uri);
   final RequestResult result = restRequest.post(index.indexPath(), data);
 }
 @Test
 public void shouldBeAbleToUseCustomReturnFilter() {
   long startNode = createBasicTraversableGraph();
   List<Object> hits =
       serialize(
           actions.traverse(
               startNode,
               MapUtil.map(
                   "prune_evaluator",
                   MapUtil.map("language", "builtin", "name", "none"),
                   "return_filter",
                   MapUtil.map(
                       "language",
                       "javascript",
                       "body",
                       "position.endNode().getProperty( 'name' ).contains( 'o' )")),
               TraverserReturnType.node));
   assertEquals(3, hits.size());
 }
Example #19
0
  private static long createGenomeElementNode(
      String version,
      String comment,
      String definition,
      BatchInserter inserter,
      BatchInserterIndex genomeElementVersionIndex,
      BatchInserterIndex nodeTypeIndex) {

    genomeElementProperties.put(GenomeElementNode.VERSION_PROPERTY, version);
    genomeElementProperties.put(GenomeElementNode.COMMENT_PROPERTY, comment);
    genomeElementProperties.put(GenomeElementNode.DEFINITION_PROPERTY, definition);

    long genomeElementId = inserter.createNode(genomeElementProperties);
    genomeElementVersionIndex.add(
        genomeElementId, MapUtil.map(GenomeElementNode.GENOME_ELEMENT_VERSION_INDEX, version));
    nodeTypeIndex.add(
        genomeElementId,
        MapUtil.map(Bio4jManager.NODE_TYPE_INDEX_NAME, GenomeElementNode.NODE_TYPE));

    return genomeElementId;
  }
 @Test
 public void testConvertJSONDataToFullPath() {
   Map<String, Object> node1 =
       MapUtil.map(
           "self",
           "http://localhost:7474/db/data/node/1",
           "data",
           MapUtil.map("propname", "testprop1"));
   Map<String, Object> node2 =
       MapUtil.map(
           "self",
           "http://localhost:7474/db/data/node/2",
           "data",
           MapUtil.map("propname", "testprop2"));
   Map<String, Object> relationship1 =
       MapUtil.map(
           "self",
           "http://localhost:7474/db/data/relationship/1",
           "data",
           MapUtil.map("propname", "testproprel1"));
   Map<String, Object> path = new HashMap<String, Object>();
   path.put("start", node1);
   path.put("nodes", asList(node1, node2));
   path.put("length", 1);
   path.put("relationships", asList(relationship1));
   path.put("end", node2);
   Object result = converter.convertToResultType(path, new TypeInformation(Path.class));
   assertEquals(SimplePath.class, result.getClass());
   assertEquals("testprop1", ((SimplePath) result).startNode().getProperty("propname"));
   assertEquals("testprop2", ((SimplePath) result).endNode().getProperty("propname"));
   assertEquals("testproprel1", ((SimplePath) result).lastRelationship().getProperty("propname"));
 }
  private long createListOfNodes(int numberOfNodes) {
    Transaction tx = database.getGraph().beginTx();
    try {
      long zerothNode = helper.createNode(MapUtil.map("name", String.valueOf(0)));
      long previousNodeId = zerothNode;
      for (int i = 1; i < numberOfNodes; i++) {
        long currentNodeId = helper.createNode(MapUtil.map("name", String.valueOf(i)));
        database
            .getGraph()
            .getNodeById(previousNodeId)
            .createRelationshipTo(
                database.getGraph().getNodeById(currentNodeId),
                DynamicRelationshipType.withName("PRECEDES"));
        previousNodeId = currentNodeId;
      }

      tx.success();
      return zerothNode;
    } finally {
      tx.finish();
    }
  }
  @Test
  public void shouldBeAbleToIndexNode() {
    String key = "mykey";
    String value = "myvalue";
    long nodeId = graphdbHelper.createNode();
    String indexName = "node";

    actions.createNodeIndex(MapUtil.map("name", indexName));

    assertFalse(serialize(actions.getIndexedNodes(indexName, key, value)).iterator().hasNext());
    actions.addToNodeIndex(indexName, key, value, nodeId);
    assertEquals(Arrays.asList(nodeId), graphdbHelper.getIndexedNodes(indexName, key, value));
  }
Example #23
0
 static EmbeddedGraphDatabase startTemporaryDb(
     String targetDirectory, VerificationLevel verification) {
   if (verification != VerificationLevel.NONE) {
     return new EmbeddedGraphDatabase(
         targetDirectory,
         MapUtil.stringMap(
             Config.INTERCEPT_DESERIALIZED_TRANSACTIONS,
             "true",
             TransactionInterceptorProvider.class.getSimpleName()
                 + "."
                 + verification.interceptorName,
             verification.configValue));
   } else return new EmbeddedGraphDatabase(targetDirectory);
 }
 private Map<String, String> config(
     Class<? extends PropertyContainer> cls, String indexName, Map<String, String> config) {
   // TODO Doesn't look right
   if (config != null) {
     config =
         MapUtil.stringMap(
             new HashMap<String, String>(config),
             "provider",
             BerkeleyDbIndexImplementation.SERVICE_NAME);
     indexStore.setIfNecessary(cls, indexName, config);
     return config;
   } else {
     return indexStore.get(cls, indexName);
   }
 }
Example #25
0
  private Pair<Map<String, String>, Boolean /*true=needs to be set*/> findIndexConfig(
      Class<? extends PropertyContainer> cls,
      String indexName,
      Map<String, String> suppliedConfig,
      Map<?, ?> dbConfig) {
    // Check stored config (has this index been created previously?)
    Map<String, String> storedConfig = indexStore.get(cls, indexName);
    if (storedConfig != null && suppliedConfig == null) {
      // Fill in "provider" if not already filled in, backwards compatibility issue
      Map<String, String> newConfig =
          injectDefaultProviderIfMissing(cls, indexName, dbConfig, storedConfig);
      if (newConfig != storedConfig) {
        indexStore.set(cls, indexName, newConfig);
      }
      return Pair.of(newConfig, Boolean.FALSE);
    }

    Map<String, String> configToUse = suppliedConfig;

    // Check db config properties for provider
    String provider = null;
    IndexImplementation indexProvider = null;
    if (configToUse == null) {
      provider = getDefaultProvider(indexName, dbConfig);
      configToUse = MapUtil.stringMap(PROVIDER, provider);
    } else {
      provider = configToUse.get(PROVIDER);
      provider = provider == null ? getDefaultProvider(indexName, dbConfig) : provider;
    }
    indexProvider = getIndexProvider(provider);
    configToUse = indexProvider.fillInDefaults(configToUse);
    configToUse = injectDefaultProviderIfMissing(cls, indexName, dbConfig, configToUse);

    // Do they match (stored vs. supplied)?
    if (storedConfig != null) {
      assertConfigMatches(indexProvider, indexName, storedConfig, suppliedConfig);
      // Fill in "provider" if not already filled in, backwards compatibility issue
      Map<String, String> newConfig =
          injectDefaultProviderIfMissing(cls, indexName, dbConfig, storedConfig);
      if (newConfig != storedConfig) {
        indexStore.set(cls, indexName, newConfig);
      }
      configToUse = newConfig;
    }

    boolean needsToBeSet = !indexStore.has(cls, indexName);
    return Pair.of(Collections.unmodifiableMap(configToUse), needsToBeSet);
  }
Example #26
0
  private static long createGenomeElementNode(
      String version,
      String comment,
      String definition,
      BatchInserter inserter,
      BatchInserterIndex index) {

    genomeElementProperties.put(GenomeElementNode.VERSION_PROPERTY, version);
    genomeElementProperties.put(GenomeElementNode.COMMENT_PROPERTY, comment);
    genomeElementProperties.put(GenomeElementNode.DEFINITION_PROPERTY, definition);

    long genomeElementId = inserter.createNode(genomeElementProperties);
    index.add(
        genomeElementId, MapUtil.map(GenomeElementNode.GENOME_ELEMENT_VERSION_INDEX, version));
    return genomeElementId;
  }
 public Node merge(
     String labelName,
     String key,
     Object value,
     final Map<String, Object> nodeProperties,
     Collection<String> labels) {
   if (labelName == null || key == null || value == null)
     throw new IllegalArgumentException(
         "Label " + labelName + " key " + key + " and value must not be null");
   Map props =
       nodeProperties.containsKey(key)
           ? nodeProperties
           : MapUtil.copyAndPut(nodeProperties, key, value);
   Map<String, Object> params = map("props", props, "value", value);
   return cypher.query(mergeQuery(labelName, key, labels), params).to(Node.class).single();
 }
Example #28
0
 public Map getQueryStatistics() {
   final Map<String, Object> stats =
       MapUtil.map(
           "rows", getRowCount(),
           "time", getTime());
   if (queryStatistics != null && queryStatistics.containsUpdates()) {
     stats.put("containsUpdates", queryStatistics.containsUpdates());
     stats.put("nodesDeleted", queryStatistics.getDeletedNodes());
     stats.put("relationshipsDeleted", queryStatistics.getDeletedRelationships());
     stats.put("nodesCreated", queryStatistics.getNodesCreated());
     stats.put("relationshipsCreated", queryStatistics.getRelationshipsCreated());
     stats.put("propertiesSet", queryStatistics.getPropertiesSet());
     stats.put("text", queryStatistics.toString());
   }
   return stats;
 }
  @Test(expected = RestResultException.class)
  public void testFailingCreateNodeAndAddToIndex() throws Exception {
    RestIndex<Node> index =
        restAPI.createIndex(
            Node.class,
            "index",
            MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext_ _"));
    final Transaction tx = restAPI.beginTx();

    Node n1 = restAPI.createNode(map());
    index.add(n1, "key", "value");

    tx.success();
    tx.finish();
    Node node = index.get("key", "value").getSingle();
    assertEquals("created node found in index", n1, node);
  }
Example #30
0
  @Test
  public void orderedResultsAreSupersetOfUnordered() throws Exception {
    // Given
    String indexName = "bobTheIndex";
    String key = "Name";
    String value = "Builder";
    long node = helper.createNode(MapUtil.map(key, value));
    helper.addNodeToIndex(indexName, key, value, node);
    helper.addNodeToIndex(indexName, "Gender", "Male", node);

    String entity =
        gen()
            .expectedStatus(200)
            .get(
                functionalTestHelper.indexNodeUri(indexName)
                    + "?query=Name:Build~0.1%20AND%20Gender:Male")
            .entity();

    Collection<?> hits = (Collection<?>) JsonHelper.jsonToSingleValue(entity);
    LinkedHashMap<String, String> nodeMapUnordered = (LinkedHashMap) hits.iterator().next();

    // When
    entity =
        gen()
            .expectedStatus(200)
            .get(
                functionalTestHelper.indexNodeUri(indexName)
                    + "?query=Name:Build~0.1%20AND%20Gender:Male&order=score")
            .entity();

    hits = (Collection<?>) JsonHelper.jsonToSingleValue(entity);
    LinkedHashMap<String, String> nodeMapOrdered = (LinkedHashMap) hits.iterator().next();

    // Then
    for (Map.Entry<String, String> unorderedEntry : nodeMapUnordered.entrySet()) {
      assertEquals(
          "wrong entry for key: " + unorderedEntry.getKey(),
          unorderedEntry.getValue(),
          nodeMapOrdered.get(unorderedEntry.getKey()));
    }
    assertTrue(
        "There should be only one extra value for the ordered map",
        nodeMapOrdered.size() == nodeMapUnordered.size() + 1);
  }