.doOnNext( RX_LOG ).take( 1 ).count() .doOnNext( count -> {
@Test @Category(ExperimentalTest.class ) public void testConnectableObserver() throws InterruptedException { final int count = 10; final CountDownLatch latch = new CountDownLatch( count ); final ConnectableObservable<Integer> connectedObservable = Observable.range( 0, count ).publish(); //connect to our latch, which should run on it's own subscription //start our latch running connectedObservable.doOnNext( integer -> latch.countDown() ).subscribeOn( Schedulers.io() ).subscribe(); final Observable<Integer> countObservable = connectedObservable.subscribeOn( Schedulers.io() ).count(); //start the sequence connectedObservable.connect(); final boolean completed = latch.await( 5, TimeUnit.SECONDS ); assertTrue( "publish1 behaves as expected", completed ); final int returnedCount = countObservable.toBlocking().last(); assertEquals( "Counts the same", count, returnedCount ); }
} ).count().defaultIfEmpty( 0 ).toBlocking().last();
@Test public void testGetEdgesToTarget() { final GraphManager gm = emf.createEdgeManager( scope ); Id sourceId1 = new SimpleId( "source1" ); Id sourceId2 = new SimpleId( "source2" ); Id targetId1 = new SimpleId( "target" ); Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, System.currentTimeMillis() ); gm.writeEdge( testTargetEdge ).toBlocking().singleOrDefault( null ); Edge testTarget2Edge = createEdge( sourceId2, "edgeType1", targetId1, System.currentTimeMillis() ); gm.writeEdge( testTarget2Edge ).toBlocking().singleOrDefault( null ); Edge test2TargetEdge = createEdge( sourceId1, "edgeType1", targetId1, System.currentTimeMillis() ); gm.writeEdge( test2TargetEdge ).toBlocking().singleOrDefault( null ); Edge test3TargetEdge = createEdge( sourceId1, "edgeType2", targetId1, System.currentTimeMillis() ); gm.writeEdge( test3TargetEdge ).toBlocking().singleOrDefault( null ); int count = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType(targetId1, null, null) ) .count().toBlocking().last(); assertEquals( 3, count ); count = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType(targetId1, "edgeType", null) ) .count().toBlocking().last(); assertEquals( 2, count ); }
/** * Simple test case that tests a single edge and removing the node. The other target node should be removed as well * since it has no other targets */ @Test public void testNoDeletionMarked() { GraphManager em = emf.createEdgeManager( scope ); Edge edge = createEdge( "source", "test", "target" ); //write the edge Edge last = em.writeEdge( edge ).toBlocking().last(); assertEquals( edge, last ); Id sourceNode = edge.getSourceNode(); UUID eventTime = UUIDGenerator.newTimeUUID(); int count = deleteListener.receive( scope, sourceNode, eventTime ).count().toBlocking().last(); assertEquals( "Mark was not set, no delete should be executed", 0, count ); }
Observable<Id> ids = this.app.getApplicationService().deleteAllEntities(appScope, 5); int count = ids.count().toBlocking().last(); Assert.assertEquals(count, 5); ids = this.app.getApplicationService().deleteAllEntities(appScope, 5); count = ids.count().toBlocking().last(); Assert.assertEquals(count, 5); this.app.waitForQueueDrainAndRefreshIndex();
@Test public void testSingleConnection() { final ApplicationScope applicationScope = new ApplicationScopeImpl( new SimpleId( "application" ) ); final GraphManager gm = graphManagerFactory.createEdgeManager( applicationScope ); //now write a single connection final Id source = new SimpleId( "source" ); //add to a collection final String collectionName = "testCollection"; final Edge collectionEdge = CpNamingUtils.createCollectionEdge( applicationScope.getApplication(), collectionName, source ); final Edge writtenCollection = gm.writeEdge( collectionEdge ).toBlocking().last(); assertNotNull("Collection edge written", writtenCollection); final Id target = new SimpleId( "target" ); final String connectionType = "testConnection"; final Edge connectionEdge = CpNamingUtils.createConnectionEdge( source, connectionType, target ); final Edge writtenConnection = gm.writeEdge( connectionEdge ).toBlocking().last(); //now run the cleanup final int count = connectionService.deDupeConnections( Observable.just( applicationScope ) ).count().toBlocking().last(); assertEquals( "No edges deleted", 0, count ); //now ensure we can read the edge. final SearchByEdge simpleSearchByEdge = new SimpleSearchByEdge( source, connectionEdge.getType(), target, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); final List<MarkedEdge> edges = gm.loadEdgeVersions( simpleSearchByEdge ).toList().toBlocking().last(); assertEquals( 1, edges.size() ); assertEquals( writtenConnection, edges.get( 0 ) ); }
int appCount = Observable.from( applicationInfoResults.getEntities() ).filter( entity -> !entity.getName().startsWith( "org." ) ).doOnNext( entity -> logger.info("counting entity {}", entity) ).count().toBlocking().last(); assertEquals( appIds.size() ,appCount );
int count = deleteListener.receive( scope, toDelete, UUIDGenerator.newTimeUUID() ).count().toBlocking().last();
int count = deleteListener.receive( scope, targetNode, UUIDGenerator.newTimeUUID() ).count().toBlocking().last();
int count = deleteListener.receive( scope, sourceNode, deleteEventTimestamp ).count().toBlocking().last();
.flatMap(mesage ->indexProducer.put(mesage)).count().toBlocking().last();
public Observable<Integer> count() { return get(Util.toOne()).count(); }
public Observable<Integer> count() { return get(Util.toOne()).count(); }
.flatMap(mesage -> indexProducer.put(mesage)).count().toBlocking().last();
.flatMap(mesage -> indexProducer.put(mesage)).count().toBlocking().last();
public static void main(String[] args) throws InterruptedException { String output = System.getProperty("output", "target/output"); // output = "/media/an/binary-fixes-2012/temp"; long sampleSeconds = Long.parseLong(System.getProperty("sampleSeconds", "0")); BinaryFixes .sortBinaryFixFilesByTime(new File(output), sampleSeconds, Schedulers.immediate()) .count().toBlocking().single(); }
public static void main(String[] args) { final File input = new File(System.getProperty("input")); final File output = new File(System.getProperty("output")); Pattern pattern = Pattern.compile(System.getProperty("pattern")); Action2<List<HasFix>, File> fixesWriter = (fixes, file) -> { BinaryFixesWriter.writeFixes(fixes, file, false, true, BinaryFixesFormat.WITHOUT_MMSI); }; Func1<String, String> renamer = name -> name + ".zip"; Formats.transform(input, output, pattern, Transformers.<HasFix> identity(), fixesWriter, renamer).count().toBlocking().single(); }
public static void sort(File output) { // now sort the data in each output file by time and rewrite List<File> files = Files.find(output, Pattern.compile(".*\\.fix")); Observable.from(files) // .buffer(Math.max(1, files.size() / Runtime.getRuntime().availableProcessors())) // .flatMap(list -> Observable.from(list) // .doOnNext(file -> sortFixFile(file)).subscribeOn(Schedulers.computation())) .count().toBlocking().single(); }
@Test public void sample_216() throws Exception { Observable<KeyEvent> keyEvents = empty(); Observable<Observable<KeyEvent>> windows = keyEvents.window(1, SECONDS); Observable<Integer> eventPerSecond = windows .flatMap(eventsInSecond -> eventsInSecond.count()); }