@Test
 public void verifyFailoverWithoutLoadBalancing() throws Exception {
   int numberOfMessages = 11;
   ConcurrentTaskExecutor taskExecutor =
       new ConcurrentTaskExecutor(
           Executors.newSingleThreadScheduledExecutor(new CustomizableThreadFactory("test-")));
   ExecutorChannel channel = new ExecutorChannel(taskExecutor, null);
   CountDownLatch latch = new CountDownLatch(numberOfMessages);
   TestHandler handler1 = new TestHandler(latch);
   TestHandler handler2 = new TestHandler(latch);
   TestHandler handler3 = new TestHandler(latch);
   channel.subscribe(handler1);
   channel.subscribe(handler2);
   channel.subscribe(handler3);
   handler1.shouldFail = true;
   for (int i = 0; i < numberOfMessages; i++) {
     channel.send(new GenericMessage<String>("test-" + i));
   }
   latch.await(3000, TimeUnit.MILLISECONDS);
   assertEquals(0, latch.getCount());
   assertNotNull(handler1.thread);
   assertFalse(Thread.currentThread().equals(handler1.thread));
   assertTrue(handler1.thread.getName().startsWith("test-"));
   assertNotNull(handler2.thread);
   assertFalse(Thread.currentThread().equals(handler2.thread));
   assertTrue(handler2.thread.getName().startsWith("test-"));
   assertNull(handler3.thread);
   assertEquals(0, handler1.count.get());
   assertEquals(0, handler3.count.get());
   assertEquals(numberOfMessages, handler2.count.get());
 }
 @Test
 public void testGeneratedFiles() throws SAXException, IOException {
   final File[] files = {
     new File("maps", "root-map-01.ditamap"),
     new File("topics", "target-topic-a.xml"),
     new File("topics", "target-topic-c.xml"),
     new File("topics", "xreffin-topic-1.xml"),
     new File("topics", "copy-to.xml"),
   };
   final Map<File, File> copyto = new HashMap<File, File>();
   copyto.put(new File("topics", "copy-to.xml"), new File("topics", "xreffin-topic-1.xml"));
   final TestHandler handler = new TestHandler();
   final XMLReader parser = XMLReaderFactory.createXMLReader();
   parser.setContentHandler(handler);
   for (final File f : files) {
     InputStream in = null;
     try {
       in = new FileInputStream(new File(tmpDir, f.getPath()));
       handler.setSource(
           new File(inputDir, copyto.containsKey(f) ? copyto.get(f).getPath() : f.getPath()));
       parser.parse(new InputSource(in));
     } finally {
       if (in != null) {
         in.close();
       }
     }
   }
 }
  private void reset() {
    clientException.set(null);
    serverException.set(null);
    clientHandler.handshakeCounter = 0;
    serverHandler.handshakeCounter = 0;
    clientChannel = null;
    serverChannel = null;

    clientSslHandler = null;
    serverSslHandler = null;
  }
  @Before
  public void setUp() throws Exception {
    File docRoot = new File("target/test-output/docroot/");
    docRoot.mkdirs();
    docRoot.deleteOnExit();

    System.setProperty("org.mortbay.jetty.util.DEBUG", "");
    _server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    _server.addConnector(connector);

    _handler = new TestHandler();
    _server.setHandler(_handler);

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    mBeanContainer.addBean(Log.getLog());

    _counter = _handler.getRequestCounter();
    mBeanContainer.addBean(_counter);

    _server.addBean(mBeanContainer);
    _server.getContainer().addEventListener(mBeanContainer);
    _server.start();

    startClient(null);

    _monitor = new JMXMonitor();

    int port = _server.getConnectors()[0].getLocalPort();
    _requestUrl = "http://localhost:" + port + "/";
  }
 private void runImportThread(GPXImporter.ImportThread importThread) {
   importThread.start();
   try {
     importThread.join();
   } catch (InterruptedException e) {
     Log.e(Settings.tag, "GPXImporterTest.runImportThread", e);
   }
   importStepHandler.waitForCompletion();
 }
  @Test // @Ignore
  public void testGetSpecifiedUser() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    try {
      Set<Attribute> attrs = fillInSampleUser(TEST_USER);

      deleteUser(TEST_USER, info);

      info.create(ObjectClass.ACCOUNT, attrs, null);

      ConnectorObject user = getUser(TEST_USER);
      Assert.assertNotNull(user);

      TestHandler handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(Uid.NAME, "asdhjfdaslfh alsk fhasldk ")),
          handler,
          null);
      Assert.assertFalse(handler.iterator().hasNext());

      handler = new TestHandler();
      String[] attributesToGet = {"firstname"};
      Map<String, Object> optionsMap = new HashMap<String, Object>();
      optionsMap.put(OperationOptions.OP_ATTRIBUTES_TO_GET, attributesToGet);
      OperationOptions options = new OperationOptions(optionsMap);
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(Uid.NAME, TEST_USER)),
          handler,
          options);
      Assert.assertTrue(handler.iterator().hasNext());
      ConnectorObject object = handler.iterator().next();
      Assert.assertNotNull(object.getAttributeByName("firstname"));
      Assert.assertNull(object.getAttributeByName("lastname"));
    } finally {
      info.dispose();
    }
  }
  private ConnectorObject getUser(String accountId, OperationOptions options) throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);

    try {
      TestHandler handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(Name.NAME, accountId)),
          handler,
          options);
      if (!handler.iterator().hasNext()) return null;
      return handler.iterator().next();
    } catch (UnknownUidException e) {
      return null;
    } finally {
      info.dispose();
    }
  }
  public void testImportGpxCancel() throws IOException {
    File gc31j2h = new File(tempDir, "gc31j2h.gpx");
    copyResourceToFile(R.raw.gc31j2h, gc31j2h);

    progressHandler.cancel();
    GPXImporter.ImportGpxFileThread importThread =
        new GPXImporter.ImportGpxFileThread(gc31j2h, listId, importStepHandler, progressHandler);
    runImportThread(importThread);

    assertImportStepMessages(
        GPXImporter.IMPORT_STEP_START,
        GPXImporter.IMPORT_STEP_READ_FILE,
        GPXImporter.IMPORT_STEP_CANCELED);
  }
  @Before
  public void setUp() throws Exception {
    handler = new TestHandler();
    bb = handler.getEditBlackboard();
    geom = bb.newGeom("newFeature", ShapeType.LINE);

    shell = geom.getShell();
    bb.addPoint(10, 10, shell);
    bb.addPoint(11, 10, shell);
    bb.addPoint(10, 10, shell);
    bb.addPoint(2, 20, shell);
    bb.addPoint(2, 20, shell);
    bb.addPoint(4000, 8000, shell);
    bb.addPoint(4000, 8000, shell);
  }
Пример #10
0
 @Override
 public void resetHandler() throws Exception {
   super.resetHandler();
 }