Package com.google.common.eventbus

Examples of com.google.common.eventbus.EventBus$EventWithHandler


    @Test
    public void removeIdentityFromNickTest(){
        File identityStoreTestFile=new File(TrConstants.IDENTITY_STORE_TEST_FILE_PATH);
        createFileIfNotExists(identityStoreTestFile);
        IdentityStore testStore=new IdentityStore(identityStoreTestFile);
        EventBus testEventBus = new EventBus();
        testStore.setEventBus(testEventBus);
        RSAPublicKey user2Key = TrCrypto.createRsaKeyPair().a;
        final String user2nick = "name2";
        UserIdentity identityTwo=new UserIdentity(user2nick, user2Key, Optional.<RSAPrivateKey>absent());
View Full Code Here


        File identityStoreTestFile=new File(TrConstants.IDENTITY_STORE_TEST_FILE_PATH);
        createFileIfNotExists(identityStoreTestFile);
        RSAPublicKey user1Key = TrCrypto.createRsaKeyPair().a;
        final String user1nick = "name2";
        IdentityStore testStore=new IdentityStore(identityStoreTestFile);
        EventBus testEventBus = new EventBus();
        testStore.setEventBus(testEventBus);
        UserIdentity identityTwo=new UserIdentity(user1nick, user1Key, Optional.<RSAPrivateKey>absent());
        final String label= "Following";

        testStore.addIdentityWithLabel(label, identityTwo);
View Full Code Here

        File identityStoreTestFile=new File(TrConstants.IDENTITY_STORE_TEST_FILE_PATH);
        createFileIfNotExists(identityStoreTestFile);
        RSAPublicKey user1Key = TrCrypto.createRsaKeyPair().a;
        final String user1nick = "name1";
        IdentityStore testStore=new IdentityStore(identityStoreTestFile);
        EventBus testEventBus = new EventBus();
        testStore.setEventBus(testEventBus);
        UserIdentity identityOne=new UserIdentity(user1nick, user1Key, Optional.<RSAPrivateKey>absent());

        testStore.addIdentityToUsersWithNickname(identityOne);
        Assert.assertTrue(testStore.getUserIdentitiesStartingWith(boundingNick).contains(identityOne));
View Full Code Here

        File identityStoreTestFile=new File(TrConstants.IDENTITY_STORE_TEST_FILE_PATH);
        createFileIfNotExists(identityStoreTestFile);
        RSAPublicKey user1Key = TrCrypto.createRsaKeyPair().a;
        final String user1nick = "name1";
        IdentityStore testStore=new IdentityStore(identityStoreTestFile);
        EventBus testEventBus = new EventBus();
        testStore.setEventBus(testEventBus);
        UserIdentity identityOne=new UserIdentity(user1nick, user1Key, Optional.<RSAPrivateKey>absent());

        testStore.addIdentityToUsersWithNickname(identityOne);
        Assert.assertTrue(testStore.getIdentitiesWithNick(identityOne.getNick()).contains(identityOne));
View Full Code Here

    @Test
    public void duplicateUsersTest(){
        File identityStoreTestFile=new File(TrConstants.IDENTITY_STORE_TEST_FILE_PATH);
        createFileIfNotExists(identityStoreTestFile);
        IdentityStore testStore=new IdentityStore(identityStoreTestFile);
        EventBus testEventBus = new EventBus();
        testStore.setEventBus(testEventBus);
        UserIdentity testUser2 = new UserIdentity("TestUser2", TrCrypto.createRsaKeyPair().a, Optional.<RSAPrivateKey>absent());

        testStore.addIdentityWithLabel("Friends", testUser2);
        testStore.addIdentityWithLabel("Friends", testUser2);
View Full Code Here

   @Test
    public void fileLoadingTest(){
       File identityStoreTestFile=new File(TrConstants.IDENTITY_STORE_TEST_FILE_PATH);
       createFileIfNotExists(identityStoreTestFile);
       IdentityStore testStore=new IdentityStore(identityStoreTestFile);
       EventBus testEventBus = new EventBus();
       testStore.setEventBus(testEventBus);

       UserIdentity testUser3 = new UserIdentity("TestUser3", TrCrypto.createRsaKeyPair().a, Optional.<RSAPrivateKey>absent());
       testStore.addIdentityWithLabel("Friends", testUser3);
       IdentityStore testStore2=new IdentityStore(identityStoreTestFile);
View Full Code Here

    // Mockups.
    final List<String> foo = Lists.newArrayList();
    for (int i = randomIntBetween(2, 1000); --i > 0;) {
      foo.add(randomAsciiOfLength(20));
    }
    final EventBus aggregatedBus = new EventBus("aggregated");

    final AtomicBoolean hadErrors = new AtomicBoolean();
   
    // Code mirrors JUnit4's behavior.
    final Deque<String> stealingQueue = new ArrayDeque<String>(foo);
    aggregatedBus.register(new Object() {
      volatile Thread foo;

      @Subscribe
      public void onSlaveIdle(SlaveIdle slave) {
        final Thread other = foo;
        if (other != null) {
          hadErrors.set(true);
          throw new RuntimeException("Wtf? two threads in a handler: "
              + other + " and " + Thread.currentThread());
        }
        foo = Thread.currentThread();
       
        if (stealingQueue.isEmpty()) {
          slave.finished();
        } else {
          String suiteName = stealingQueue.pop();
          slave.newSuite(suiteName);
        }
       
        foo = null;
      }
    });
   
    // stress.
    ExecutorService executor = Executors.newCachedThreadPool();
    final List<Callable<Void>> slaves = Lists.newArrayList();
    for (int i = 0; i < randomIntBetween(1, 10); i++) {
      slaves.add(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
          aggregatedBus.post(new SlaveIdle());
          return null;
        }
      });
    }
    for (Future<Void> f : executor.invokeAll(slaves)) {
View Full Code Here

    // Process test classes and resources.
    long start = System.currentTimeMillis();   
    final TestsCollection testCollection = processTestResources();

    final EventBus aggregatedBus = new EventBus("aggregated");
    final TestsSummaryEventListener summaryListener = new TestsSummaryEventListener();
    aggregatedBus.register(summaryListener);
   
    for (Object o : listeners) {
      if (o instanceof ProjectComponent) {
        ((ProjectComponent) o).setProject(getProject());
      }
      if (o instanceof AggregatedEventListener) {
        ((AggregatedEventListener) o).setOuter(this);
      }
      aggregatedBus.register(o);
    }

    if (testCollection.testClasses.isEmpty()) {
      aggregatedBus.post(new AggregatedQuitEvent());
    } else {
      start = System.currentTimeMillis();

      // Check if we allow duplicate suite names. Some reports (ANT compatible XML
      // reports) will have a problem with duplicate suite names, for example.
      if (uniqueSuiteNames) {
        testCollection.onlyUniqueSuiteNames();
      }

      final int jvmCount = determineForkedJvmCount(testCollection);
      final List<ForkedJvmInfo> slaveInfos = Lists.newArrayList();
      for (int jvmid = 0; jvmid < jvmCount; jvmid++) {
        final ForkedJvmInfo slaveInfo = new ForkedJvmInfo(jvmid, jvmCount);
        slaveInfos.add(slaveInfo);
      }

     
      if (jvmCount > 1 && uniqueSuiteNames && testCollection.hasReplicatedSuites()) {
        throw new BuildException(String.format(Locale.ENGLISH,
            "There are test suites that request JVM replication and the number of forked JVMs %d is larger than 1. Run on a single JVM.",
            jvmCount));
      }

      // Prepare a pool of suites dynamically dispatched to slaves as they become idle.
      final Deque<String> stealingQueue =
          new ArrayDeque<String>(loadBalanceSuites(slaveInfos, testCollection, balancers));
      aggregatedBus.register(new Object() {
        @Subscribe
        public void onSlaveIdle(SlaveIdle slave) {
          if (stealingQueue.isEmpty()) {
            slave.finished();
          } else {
            String suiteName = stealingQueue.pop();
            slave.newSuite(suiteName);
          }
        }
      });
     
      // Check for filtering expressions.
      @SuppressWarnings("unchecked")
      Vector<Variable> vv = getCommandline().getSystemProperties().getVariablesVector();
      for (Variable v : vv) {
        if (SysGlobals.SYSPROP_TESTFILTER().equals(v.getKey())) {
          try {
            Node root = new FilterExpressionParser().parse(v.getValue());
            log("Parsed test filtering expression: " + root.toExpression(), Project.MSG_INFO);
          } catch (Exception e) {
            log("Could not parse filtering expression: " + v.getValue(), Project.MSG_WARN);
          }
        }
      }

      // Create callables for the executor.
      final List<Callable<Void>> slaves = Lists.newArrayList();
      for (int slave = 0; slave < jvmCount; slave++) {
        final ForkedJvmInfo slaveInfo = slaveInfos.get(slave);
        slaves.add(new Callable<Void>() {
          @Override
          public Void call() throws Exception {
            executeSlave(slaveInfo, aggregatedBus);
            return null;
          }
        });
      }

      ExecutorService executor = Executors.newCachedThreadPool();
      aggregatedBus.post(new AggregatedStartEvent(slaves.size(),
          // TODO: this doesn't account for replicated suites.
          testCollection.testClasses.size()));

      try {
        List<Future<Void>> all = executor.invokeAll(slaves);
        executor.shutdown();

        for (int i = 0; i < slaves.size(); i++) {
          Future<Void> f = all.get(i);
          try {
            f.get();
          } catch (ExecutionException e) {
            slaveInfos.get(i).executionError = e.getCause();
          }
        }
      } catch (InterruptedException e) {
        log("Master interrupted? Weird.", Project.MSG_ERR);
      }
      aggregatedBus.post(new AggregatedQuitEvent());

      for (ForkedJvmInfo si : slaveInfos) {
        if (si.start > 0 && si.end > 0) {
          log(String.format(Locale.ENGLISH, "JVM J%d: %8.2f .. %8.2f = %8.2fs",
              si.id,
View Full Code Here

    log("Forked JVM process command line (may need escape sequences for your shell):\n" +
        slave.slaveCommandLine, Project.MSG_VERBOSE);

    commandline.createArgument().setValue(SlaveMain.OPTION_STDIN);

    final EventBus eventBus = new EventBus("slave-" + slave.id);
    final DiagnosticsListener diagnosticsListener = new DiagnosticsListener(slave, this);
    eventBus.register(diagnosticsListener);
    eventBus.register(new AggregatingListener(aggregatedBus, slave));

    final AtomicReference<Charset> clientCharset = new AtomicReference<Charset>();
    final AtomicBoolean clientWithLimitedCharset = new AtomicBoolean();
    final PrintWriter w = new PrintWriter(Files.newWriter(classNamesDynamic, Charsets.UTF_8));
    eventBus.register(new Object() {
      @Subscribe
      public void onIdleSlave(final SlaveIdle idleSlave) {
        aggregatedBus.post(new SlaveIdle() {
          @Override
          public void finished() {
View Full Code Here

    @Test
    public void shouldReceiveMultipleEvents() throws Exception {

        // given
        EventBus eventBus = new EventBus("test");
        MultipleListener multiListener = new MultipleListener();

        eventBus.register(multiListener);


        // when
        eventBus.post(new Integer(100));
        eventBus.post(new Long(800));

        // then
        assertThat(multiListener.getLastInteger()).isEqualTo(100);
        assertThat(multiListener.getLastLong()).isEqualTo(800L);
    }
View Full Code Here

TOP

Related Classes of com.google.common.eventbus.EventBus$EventWithHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.