public void test_threadSafe() throws InterruptedException, ExecutionException {
  final long eventHistoryMillis=1000L;
  final EventBTree eventBTree=EventBTree.createTransient();
  final EventReceiver eventReceiver=new EventReceiver(eventHistoryMillis,eventBTree);
  final IBigdataFederation fed=new MockFederation(eventReceiver);
  final ExecutorService exService=Executors.newCachedThreadPool(DaemonThreadFactory.defaultThreadFactory());
  final int nthreads=10;
  final int nevents=100;
  try {
    final List<Callable<Void>> tasks=new LinkedList<Callable<Void>>();
    for (int i=0; i < nthreads; i++) {
      tasks.add(new EventFactory(fed,nevents));
    }
    tasks.add(new EventConsumer(eventReceiver));
    final List<Future<Void>> futures=exService.invokeAll(tasks);
    for (    Future f : futures) {
      f.get();
    }
  }
  finally {
    exService.shutdownNow();
  }
}

public void test_threadSafe ( ) throws InterruptedException , ExecutionException { final long eventHistoryMillis = 1000L ; final EventBTree eventBTree = EventBTree . createTransient ( ) ; final EventReceiver eventReceiver = new EventReceiver ( eventHistoryMillis , eventBTree ) ; final IBigdataFederation fed = new MockFederation ( eventReceiver ) ; final ExecutorService exService = Executors . newCachedThreadPool ( DaemonThreadFactory . defaultThreadFactory ( ) ) ; final int nthreads = 10 ; final int nevents = 100 ; try { final List < Callable < Void > > tasks = new LinkedList < Callable < Void > > ( ) ; for ( int i = 0 ; i < nthreads ; i ++ ) { tasks . add ( new EventFactory ( fed , nevents ) ) ; } tasks . add ( new EventConsumer ( eventReceiver ) ) ; final List < Future < Void > > futures = exService . invokeAll ( tasks ) ; for ( Future f : futures ) { f . get ( ) ; } } finally { exService . shutdownNow ( ) ; } }
unit tests verifies that the apis are thread - safe .
