private void advance(){ //map to our old results objects, return a default empty if required final Observable<Results> observable = buildNewResultsPage( cursor ).map( resultsPage -> createResultsInternal( resultsPage ) ).defaultIfEmpty( new Results() ); if (logger.isTraceEnabled()) { logger.trace("Trying to load results page"); } //take the first from our observable final Results resultsPage = observable.take(1).toBlocking().first(); if (logger.isTraceEnabled()) { logger.trace("Results page loaded {}", resultsPage); } //set the results for the iterator this.results = resultsPage; //set the complete flag this.complete = !resultsPage.hasCursor(); //if not comlete, set our cursor for the next iteration if(!complete){ this.cursor = Optional.of( results.getCursor()); }else{ this.cursor = Optional.absent(); } }
query.setCursor( results.getCursor() );
query.setCursor( results.getCursor() );
query.setCursor( results.getCursor() );
query.setCursor(r.getCursor());
@Test public void nameIdentifierTest() throws Exception { logger.debug( "nameIdentifierTest" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put( "keywords", "blah,test,game" ); properties.put( "title", "Solitaire" ); properties.put( "name", "test" ); Entity game1 = em.create( "games", properties ); assertNotNull( game1 ); //we create 2 entities, otherwise this test will pass when it shouldn't properties.put( "name", "test2" ); Entity game2 = em.create( "game", properties ); assertNotNull( game2 ); app.waitForQueueDrainAndRefreshIndex(); // overlap Query query = new Query(); query.addIdentifier( Identifier.fromName( "test" ) ); Results r = em.searchCollection( em.getApplicationRef(), "games", query ); assertEquals( "We should only get 1 result", 1, r.size() ); assertNull( "No cursor should be present", r.getCursor() ); assertEquals( "Saved entity returned", game1, r.getEntity() ); }
assertNull(r.getCursor());
@Test public void uuidIdentifierTest() throws Exception { logger.debug( "uuidIdentifierTest" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put( "keywords", "blah,test,game" ); properties.put( "title", "Solitaire" ); Entity game1 = em.create( "game", properties ); assertNotNull( game1 ); //we create 2 entities, otherwise this test will pass when it shouldn't Entity game2 = em.create( "game", properties ); assertNotNull( game2 ); app.waitForQueueDrainAndRefreshIndex(); // overlap Query query = new Query(); query.addIdentifier( Identifier.fromUUID( game1.getUuid() ) ); Results r = em.searchCollection( em.getApplicationRef(), "games", query ); assertEquals( "We should only get 1 result", 1, r.size() ); assertNull( "No cursor should be present", r.getCursor() ); assertEquals( "Saved entity returned", game1, r.getEntity() ); }
Results r = em.searchCollection( em.getApplicationRef(), "games", query ); assertEquals( 0, r.size() ); assertNull(r.getCursor()); r = em.searchCollection( em.getApplicationRef(), "games", query ); assertEquals( 1, r.size() ); assertNotNull(r.getCursor()); assertEquals(entity2, r.getEntities().get(0)); .withCursor( r.getCursor() ); r = em.searchCollection( em.getApplicationRef(), "games", query ); assertEquals(1, r.size()); assertNotNull(r.getCursor()); assertEquals(entity1, r.getEntities().get(0)); .withCursor( r.getCursor() ); r = em.searchCollection( em.getApplicationRef(), "games", query ); assertEquals(0, r.size()); assertNull(r.getCursor());
private int countEntities( EntityManager em, String collectionName, int expectedEntities) throws Exception { app.waitForQueueDrainAndRefreshIndex(); Query q = Query.fromQL( "select * where key1=1000" ).withLimit( 1000 ); Results results = em.searchCollectionConsistent( em.getApplicationRef(), collectionName, q, expectedEntities ); int count = 0; while ( true ) { count += results.size(); if ( results.hasCursor() ) { logger.info( "Counted {} : query again with cursor", count ); q.setCursor( results.getCursor() ); results = em.searchCollection( em.getApplicationRef(), collectionName, q ); } else { break; } } assertEquals( "Did not get expected entities", expectedEntities, count ); return count; }
private int countEntities( EntityManager em, String collectionName, int expectedEntities) throws Exception { app.waitForQueueDrainAndRefreshIndex(); Query q = Query.fromQL( "select * where key1=1000" ).withLimit( 1000 ); Results results = em.searchCollectionConsistent( em.getApplicationRef(), collectionName, q, expectedEntities ); int count = 0; while ( true ) { count += results.size(); if ( results.hasCursor() ) { logger.info( "Counted {} : query again with cursor", count ); q.setCursor( results.getCursor() ); results = em.searchCollection( em.getApplicationRef(), collectionName, q ); } else { break; } } assertEquals( "Did not get expected entities", expectedEntities, count ); return count; }
private int readData( EntityManager em, String collectionName, int expectedEntities, int expectedConnections ) throws Exception { app.waitForQueueDrainAndRefreshIndex(); Query q = Query.fromQL( "select * where key1=1000" ).withLimit( 1000 ); Results results = em.searchCollectionConsistent( em.getApplicationRef(), collectionName, q, expectedEntities ); int count = 0; while ( true ) { for ( Entity e : results.getEntities() ) { assertEquals( 2000, e.getProperty( "key2" ) ); Results catResults = em.searchTargetEntities( e, Query.fromQL( "select *" ).setConnectionType( "herds" ) ); assertEquals( expectedConnections, catResults.size() ); if ( count % 100 == 0 ) { logger.info( "read {} entities", count ); } count++; } if ( results.hasCursor() ) { logger.info( "Counted {} : query again with cursor", count ); q.setCursor( results.getCursor() ); results = em.searchCollection( em.getApplicationRef(), collectionName, q ); } else { break; } } return count; }
@Test public void emailIdentifierTest() throws Exception { logger.debug( "emailIdentifierTest" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); User user = new User(); user.setUsername( "foobar" ); user.setEmail( "foobar@usergrid.org" ); Entity createUser = em.create( user ); assertNotNull( createUser ); //we create 2 entities, otherwise this test will pass when it shouldn't User user2 = new User(); user2.setUsername( "foobar2" ); user2.setEmail( "foobar2@usergrid.org" ); Entity createUser2 = em.create( user2 ); assertNotNull( createUser2 ); app.waitForQueueDrainAndRefreshIndex(); // overlap Query query = new Query(); query.addIdentifier( Identifier.fromEmail( "foobar@usergrid.org" ) ); Results r = em.searchCollection( em.getApplicationRef(), "users", query ); assertEquals( "We should only get 1 result", 1, r.size() ); assertNull( "No cursor should be present", r.getCursor() ); assertEquals( "Saved entity returned", createUser, r.getEntity() ); }