### Question:
ContinuousNodeSelector implements NodeSelector { @Override public Node selectNode(GraphDatabaseService database) { int attempt = 0; while (true) { try { if (++attempt == 1000) { LOG.warn("Did not find a suitable node in 1000 attempts. Are you sure the node inclusion policy is set correctly for ContinuousNodeSelector?"); } if (attempt == 1_000_000) { LOG.warn("Did not find a suitable node in 1M attempts. Aborting..."); return null; } Node node = database.getNodeById(nextId(database)); if (inclusionPolicy.include(node)) { return node; } } catch (NotFoundException e) { } } } ContinuousNodeSelector();  ContinuousNodeSelector(long lastNodeId);  ContinuousNodeSelector(NodeInclusionPolicy inclusionPolicy);  ContinuousNodeSelector(NodeInclusionPolicy inclusionPolicy, long lastNodeId); @Override Node selectNode(GraphDatabaseService database);  }### Answer:
@Test public void shouldSelectCorrectNodes() { NodeSelector selector = new ContinuousNodeSelector(IncludeNodes.all().with(label("Person"))); try (Transaction tx = getDatabase().beginTx()) { assertEquals("Michal", selector.selectNode(getDatabase()).getProperty("name")); assertEquals("Daniela", selector.selectNode(getDatabase()).getProperty("name")); assertEquals("Adam", selector.selectNode(getDatabase()).getProperty("name")); assertEquals("Michal", selector.selectNode(getDatabase()).getProperty("name")); assertEquals("Daniela", selector.selectNode(getDatabase()).getProperty("name")); assertEquals("Adam", selector.selectNode(getDatabase()).getProperty("name")); tx.success(); } }
@Test public void shouldResumeFromLastNode() { NodeSelector selector = new ContinuousNodeSelector(IncludeNodes.all().with(label("Person")), 2L); try (Transaction tx = getDatabase().beginTx()) { assertEquals("Adam", selector.selectNode(getDatabase()).getProperty("name")); assertEquals("Michal", selector.selectNode(getDatabase()).getProperty("name")); assertEquals("Daniela", selector.selectNode(getDatabase()).getProperty("name")); assertEquals("Adam", selector.selectNode(getDatabase()).getProperty("name")); tx.success(); } }
@Test public void shouldTerminateWhenNoSuitableNodesExist() { NodeSelector selector = new ContinuousNodeSelector(IncludeNoNodes.getInstance()); try (Transaction tx = getDatabase().beginTx()) { selector.selectNode(getDatabase()); tx.success(); } }