List of usage examples for java.util.concurrent.atomic AtomicBoolean set
public final void set(boolean newValue)
From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java
@Test public void testThatNamedPipeThrows() throws IOException, InterruptedException { Assume.assumeFalse(Platform.isWindows()); final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String FIFO_NAME = "bFifo"; final AtomicBoolean caughtException = new AtomicBoolean(false); try {/* ww w . j a v a 2 s. c o m*/ Runtime.getRuntime().exec("mkfifo " + Paths.get(tempDirectory.toString(), FIFO_NAME)).waitFor(); new FileObjectPutter(tempDirectory).buildChannel(FIFO_NAME); } catch (final UnrecoverableIOException e) { assertTrue(e.getMessage().contains(FIFO_NAME)); caughtException.set(true); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } assertTrue(caughtException.get()); }
From source file:org.apache.hadoop.hbase.ipc.TestAsyncIPC.java
@Test public void testRTEDuringAsyncConnectionSetup() throws Exception { TestRpcServer rpcServer = new TestRpcServer(); AsyncRpcClient client = createRpcClientRTEDuringConnectionSetup(CONF); try {/*from w w w . j a v a2 s.co m*/ rpcServer.start(); InetSocketAddress address = rpcServer.getListenerAddress(); MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo"); EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build(); RpcChannel channel = client.createRpcChannel( ServerName.valueOf(address.getHostName(), address.getPort(), System.currentTimeMillis()), User.getCurrent(), 0); final AtomicBoolean done = new AtomicBoolean(false); PayloadCarryingRpcController controller = new PayloadCarryingRpcController(); controller.notifyOnFail(new RpcCallback<IOException>() { @Override public void run(IOException e) { done.set(true); LOG.info("Caught expected exception: " + e.toString()); assertTrue(StringUtils.stringifyException(e).contains("Injected fault")); } }); channel.callMethod(md, controller, param, md.getOutputType().toProto(), new RpcCallback<Message>() { @Override public void run(Message parameter) { done.set(true); fail("Expected an exception to have been thrown!"); } }); TEST_UTIL.waitFor(1000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return done.get(); } }); } finally { client.close(); rpcServer.stop(); } }
From source file:core.nipr.NiprClient.java
public Map<String, LicenseInternal> getSpecificReport(GregorianCalendar aInDate, AtomicBoolean aOutFailure, StringBuilder aInOutErrors) { Map<String, LicenseInternal> lAllLicenses = new HashMap<String, LicenseInternal>(); aOutFailure.set(false); ReceiveSpecificReport lRequest = new ReceiveSpecificReport(); /*//from w w w. j av a 2 s. c o m Date lDate = new Date(); GregorianCalendar c = new GregorianCalendar(); c.setTime(lDate); */ String formatted = CalenderUtils.getFormattedDate(aInDate); System.out.println("Getting Record for ====================== " + formatted); try { XMLGregorianCalendar lXmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(aInDate); lRequest.setReportDate(lXmlDate); Object lSoapResponse = getWebServiceTemplate().marshalSendAndReceive(lRequest, new SoapActionCallback(getDefaultUri().replace("/services", "") + "/receiveSpecificReport")); System.out.println("NIPR soap api SUCCESS ++++++++++++ " + formatted); ReceiveSpecificReportResponse lResponse = (ReceiveSpecificReportResponse) lSoapResponse; AlertsReportType lType = lResponse.getAlertsReport(); DataHandler lHandler = lType.getAlertsReport(); //String theString = IOUtils.toString(lHandler.getInputStream(), "utf-8"); //System.out.println("Response " + theString); lAllLicenses = parseReport(lType.getAlertsReport().getInputStream(), lXmlDate); System.out.println("Total NIPR Liceses for " + formatted + " are " + lAllLicenses.size()); } catch (SoapFaultClientException e) { aOutFailure.set(true); try { PdbAlertsFaultType lFaultType = getDetailedFault(e); if (lFaultType != null) { System.out.println("NiprSoapApi error from server " + lFaultType.getMessage()); if (lFaultType.getErrorCode() == 5) { aOutFailure.set(false); System.out.println( "Treating no Nipr alerts for the day " + formatted + " as SUCCESS ++++++++++"); } } } catch (Exception ex) { aOutFailure.set(true); String lMsg = "NiprSoapApi SoapFaultClientException error in parsing the exception " + ex.getMessage(); WebUtils.appendline(lMsg, aInOutErrors); System.out.println(lMsg); } } catch (Exception e) { aOutFailure.set(true); e.printStackTrace(); String lMsg = "NiprSoapApi generic exception " + e.getMessage(); WebUtils.appendline(lMsg, aInOutErrors); System.out.println(lMsg); } return lAllLicenses; }
From source file:io.restassured.examples.springmvc.controller.AutoSpringSecurityConfigurerITest.java
@Test public void doesnt_add_spring_security_configurer_automatically_when_a_spring_security_configurer_has_been_manually_applied() { final AtomicBoolean filterUsed = new AtomicBoolean(false); RestAssuredMockMvc.given().webAppContextSetup(context, springSecurity(), springSecurity(new Filter() { public void init(FilterConfig filterConfig) throws ServletException { }// ww w . j a v a 2 s . co m public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { filterUsed.set(true); chain.doFilter(request, response); } public void destroy() { } })).postProcessors(httpBasic("username", "password")).param("name", "Johan").when().get("/secured/greeting") .then().statusCode(200).body("content", equalTo("Hello, Johan!")) .expect(authenticated().withUsername("username")); assertThat(filterUsed.get(), is(true)); }
From source file:com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions.java
@Override public boolean enableOnly(Principal principal, Set<Action> actions) { final AtomicBoolean result = new AtomicBoolean(false); getAvailableActions().stream().forEach(available -> { available.stream().forEach(child -> { if (actions.contains(child)) { result.set(togglePermission(child, principal, true) || result.get()); } else { togglePermission(child, principal, false); }/*from w ww .j a va2 s. c om*/ }); }); return result.get(); }
From source file:io.dyn.core.handler.AnnotationHandlerMethodResolver.java
@Override public boolean supports(final Class<?> aClass) { boolean classLevelAnno = (null != AnnotationUtils.findAnnotation(aClass, Handler.class)); final AtomicBoolean hasHandlerMethod = new AtomicBoolean(false); Class<?> clazz = aClass; while (null != clazz && clazz != Object.class) { ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() { @Override/* w ww. j ava 2 s. c om*/ public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { if (!hasHandlerMethod.get()) { hasHandlerMethod.set(true); } } }, Handlers.USER_METHODS); clazz = clazz.getSuperclass(); } return (hasHandlerMethod.get() || classLevelAnno); }
From source file:org.apache.hadoop.hive.ql.txn.compactor.TestCleaner.java
@Test public void notBlockedBySubsequentLock() throws Exception { Table t = newTable("default", "bblt", false); // Set the run frequency low on this test so it doesn't take long conf.setTimeVar(HiveConf.ConfVars.HIVE_COMPACTOR_CLEANER_RUN_INTERVAL, 100, TimeUnit.MILLISECONDS); addBaseFile(t, null, 20L, 20);//from w w w . j av a2 s . c om addDeltaFile(t, null, 21L, 22L, 2); addDeltaFile(t, null, 23L, 24L, 2); addDeltaFile(t, null, 21L, 24L, 4); burnThroughTransactions(25); CompactionRequest rqst = new CompactionRequest("default", "bblt", CompactionType.MINOR); txnHandler.compact(rqst); CompactionInfo ci = txnHandler.findNextToCompact("fred"); txnHandler.markCompacted(ci); txnHandler.setRunAs(ci.id, System.getProperty("user.name")); LockComponent comp = new LockComponent(LockType.SHARED_READ, LockLevel.TABLE, "default"); comp.setTablename("bblt"); List<LockComponent> components = new ArrayList<LockComponent>(1); components.add(comp); LockRequest req = new LockRequest(components, "me", "localhost"); LockResponse res = txnHandler.lock(req); AtomicBoolean looped = new AtomicBoolean(); looped.set(false); startCleaner(looped); // Make sure the compactor has a chance to run once while (!looped.get()) { Thread.currentThread().sleep(100); } // There should still be one request, as the locks still held. ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest()); List<ShowCompactResponseElement> compacts = rsp.getCompacts(); Assert.assertEquals(1, compacts.size()); // obtain a second lock. This shouldn't block cleaner as it was acquired after the initial // clean request LockComponent comp2 = new LockComponent(LockType.SHARED_READ, LockLevel.TABLE, "default"); comp2.setTablename("bblt"); List<LockComponent> components2 = new ArrayList<LockComponent>(1); components2.add(comp2); LockRequest req2 = new LockRequest(components, "me", "localhost"); LockResponse res2 = txnHandler.lock(req2); // Unlock the previous lock txnHandler.unlock(new UnlockRequest(res.getLockid())); looped.set(false); while (!looped.get()) { Thread.currentThread().sleep(100); } stopThread(); Thread.currentThread().sleep(200); // Check there are no compactions requests left. rsp = txnHandler.showCompact(new ShowCompactRequest()); compacts = rsp.getCompacts(); Assert.assertEquals(0, compacts.size()); }
From source file:net.sourceforge.ganttproject.io.CsvImportTest.java
public void testTwoGroups() throws Exception { String header1 = "A, B"; String data1 = "a1, b1"; final AtomicBoolean wasCalled1 = new AtomicBoolean(false); GanttCSVOpen.RecordGroup recordGroup1 = new GanttCSVOpen.RecordGroup("AB", ImmutableSet.<String>of("A", "B")) { @Override/*from w w w . j a va 2s . c o m*/ protected boolean doProcess(CSVRecord record) { assertEquals("a1", record.get("A")); assertEquals("b1", record.get("B")); wasCalled1.set(true); return true; } }; String header2 = "C, D, E"; String data2 = "c1, d1, e1"; final AtomicBoolean wasCalled2 = new AtomicBoolean(false); GanttCSVOpen.RecordGroup recordGroup2 = new GanttCSVOpen.RecordGroup("CDE", ImmutableSet.<String>of("C", "D", "E")) { @Override protected boolean doProcess(CSVRecord record) { assertEquals("c1", record.get("C")); assertEquals("d1", record.get("D")); assertEquals("e1", record.get("E")); wasCalled2.set(true); return true; } }; GanttCSVOpen importer = new GanttCSVOpen( createSupplier(Joiner.on('\n').join(header1, data1, "", header2, data2)), recordGroup1, recordGroup2); importer.load(); assertTrue(wasCalled1.get() && wasCalled2.get()); }
From source file:org.apache.hadoop.hive.ql.txn.compactor.TestCleaner.java
@Test public void partitionNotBlockedBySubsequentLock() throws Exception { Table t = newTable("default", "bblt", true); Partition p = newPartition(t, "today"); // Set the run frequency low on this test so it doesn't take long conf.setTimeVar(HiveConf.ConfVars.HIVE_COMPACTOR_CLEANER_RUN_INTERVAL, 100, TimeUnit.MILLISECONDS); addBaseFile(t, p, 20L, 20);//from ww w . j a va2 s.c om addDeltaFile(t, p, 21L, 22L, 2); addDeltaFile(t, p, 23L, 24L, 2); addDeltaFile(t, p, 21L, 24L, 4); burnThroughTransactions(25); CompactionRequest rqst = new CompactionRequest("default", "bblt", CompactionType.MINOR); rqst.setPartitionname("ds=today"); txnHandler.compact(rqst); CompactionInfo ci = txnHandler.findNextToCompact("fred"); txnHandler.markCompacted(ci); txnHandler.setRunAs(ci.id, System.getProperty("user.name")); LockComponent comp = new LockComponent(LockType.SHARED_READ, LockLevel.PARTITION, "default"); comp.setTablename("bblt"); comp.setPartitionname("ds=today"); List<LockComponent> components = new ArrayList<LockComponent>(1); components.add(comp); LockRequest req = new LockRequest(components, "me", "localhost"); LockResponse res = txnHandler.lock(req); AtomicBoolean looped = new AtomicBoolean(); looped.set(false); startCleaner(looped); // Make sure the compactor has a chance to run once while (!looped.get()) { Thread.currentThread().sleep(100); } // There should still be one request, as the locks still held. ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest()); List<ShowCompactResponseElement> compacts = rsp.getCompacts(); Assert.assertEquals(1, compacts.size()); // obtain a second lock. This shouldn't block cleaner as it was acquired after the initial // clean request LockComponent comp2 = new LockComponent(LockType.SHARED_READ, LockLevel.PARTITION, "default"); comp2.setTablename("bblt"); comp2.setPartitionname("ds=today"); List<LockComponent> components2 = new ArrayList<LockComponent>(1); components2.add(comp2); LockRequest req2 = new LockRequest(components, "me", "localhost"); LockResponse res2 = txnHandler.lock(req2); // Unlock the previous lock txnHandler.unlock(new UnlockRequest(res.getLockid())); looped.set(false); while (!looped.get()) { Thread.currentThread().sleep(100); } stopThread(); Thread.currentThread().sleep(200); // Check there are no compactions requests left. rsp = txnHandler.showCompact(new ShowCompactRequest()); compacts = rsp.getCompacts(); Assert.assertEquals(0, compacts.size()); }
From source file:org.apache.hadoop.hbase.ipc.TestAsyncIPC.java
@Test public void testAsyncConnectionSetup() throws Exception { TestRpcServer rpcServer = new TestRpcServer(); AsyncRpcClient client = createRpcClient(CONF); try {//from www . j a va 2 s. c o m rpcServer.start(); InetSocketAddress address = rpcServer.getListenerAddress(); MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo"); EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build(); RpcChannel channel = client.createRpcChannel( ServerName.valueOf(address.getHostName(), address.getPort(), System.currentTimeMillis()), User.getCurrent(), 0); final AtomicBoolean done = new AtomicBoolean(false); channel.callMethod(md, new PayloadCarryingRpcController(), param, md.getOutputType().toProto(), new RpcCallback<Message>() { @Override public void run(Message parameter) { done.set(true); } }); TEST_UTIL.waitFor(1000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return done.get(); } }); } finally { client.close(); rpcServer.stop(); } }