/** * Performs clustering using {@link Controller}. * * @param documents Documents to be clustered. * @return {@link ProcessingResult} returned from the controller. */ public ProcessingResult cluster(Collection<Document> documents) { processingAttributes.put(AttributeNames.DOCUMENTS, documents); Controller controller = getSimpleController(initAttributes); try { ProcessingResult process = controller.process(processingAttributes, getComponentClass()); return process; } finally { controller.dispose(); super.simpleController = null; } }
@SuppressWarnings("unchecked") @Test @ThreadLeakLingering(linger = 5000) public void testRepeatedClusteringWithCache() { // Caching controller is not available for .NET at the moment. assumeTrue("Java test only.", Platform.getPlatform() == Platform.JAVA); final Controller controller = getCachingController(initAttributes, IClusteringAlgorithm.class); final Map<String, Object> processingAttributes = ImmutableMap.of(AttributeNames.DOCUMENTS, (Object) DOCUMENTS_DATA_MINING); controller.process(processingAttributes, getComponentClass()); controller.process(processingAttributes, getComponentClass()); controller.dispose(); }
@Test public void checkBasicAuthAccess() throws Throwable { final Server server = new Server(); final SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(/* any */ 0); connector.setReuseAddress(false); connector.setSoLingerTime(0); server.addConnector(connector); HashLoginService loginService = new HashLoginService(); loginService.putUser("username", new Password("userpass"), new String[] {"role1", "role2"}); final CountDownLatch latch = new CountDownLatch(1); WebAppContext wac = new WebAppContext(); wac.getSecurityHandler().setLoginService(loginService); wac.setContextPath("/"); connector.addLifeCycleListener( new ListenerAdapter() { public void lifeCycleStarted(LifeCycle lc) { System.out.println("Started on port: " + connector.getLocalPort()); latch.countDown(); } public void lifeCycleFailure(LifeCycle lc, Throwable t) { System.out.println("Failure: " + t); latch.countDown(); } }); wac.setParentLoaderPriority(true); URL resource = getClass().getResource("/auth/basic/kaczynski.xml"); assertThat(resource.toURI().getScheme()).isEqualTo("file"); File webapp = new File(resource.toURI()); webapp = webapp.getParentFile(); // /auth/basic webapp = webapp.getParentFile(); // /auth wac.setWar(webapp.getAbsolutePath()); wac.setClassLoader(Thread.currentThread().getContextClassLoader()); server.setHandler(wac); server.setStopAtShutdown(true); try { server.start(); latch.await(); System.setProperty(HttpAuthHub.USERNAME_PROPERTY, "username"); System.setProperty(HttpAuthHub.PASSWORD_PROPERTY, "userpass"); Controller c = ControllerFactory.createSimple(); try { Map<String, Object> attrs = new HashMap<String, Object>(); XmlDocumentSourceDescriptor.attributeBuilder(attrs) .xml( new URLResourceWithParams( new URL( "http://localhost:" + connector.getLocalPort() + "/basic/kaczynski.xml"))); ProcessingResult r = c.process(attrs, XmlDocumentSource.class); assertThat(r.getDocuments()).hasSize(50); } finally { c.dispose(); } } finally { server.stop(); } }