List of usage examples for org.apache.commons.lang3.mutable MutableBoolean isTrue
public boolean isTrue()
true
. From source file:com.ibm.jaggr.core.impl.cache.GzipCacheImplTest.java
@SuppressWarnings("unchecked") @Test/* w w w .j a v a 2s.c om*/ public void testGetInputStreamExceptionHandling() throws Exception { final GzipCacheImpl impl = new GzipCacheImpl(); EasyMock.replay(mockAggregator, mockCacheManager); impl.setAggregator(mockAggregator); final MutableInt retLength = new MutableInt(); final CountDownLatch latch3 = new CountDownLatch(1); EasyMock.reset(mockCacheManager); EasyMock.expect(mockCacheManager.getCacheDir()).andReturn(tempdir).anyTimes(); mockCacheManager.createCacheFileAsync(EasyMock.isA(String.class), EasyMock.isA(InputStream.class), EasyMock.isA(ICacheManager.CreateCompletionCallback.class)); EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { latch1.countDown(); latch2.await(); throw new IOException("test generated exception"); } }).anyTimes(); EasyMock.replay(mockCacheManager); // get input stream (should throw execption because file was deleted final MutableBoolean exceptionCaught = new MutableBoolean(false); new Thread(new Runnable() { @Override public void run() { try { InputStream is = impl.getInputStream("key", tempfile.toURI(), retLength); } catch (Exception ex) { exceptionCaught.setTrue(); } latch3.countDown(); } }).start(); latch1.await(); IGzipCache.ICacheEntry cacheEntry = impl.get("key"); latch2.countDown(); latch3.await(); Assert.assertTrue(exceptionCaught.isTrue()); Assert.assertNotNull(Whitebox.getInternalState(cacheEntry, "ex")); Assert.assertNull(impl.get("key")); }
From source file:de.uni_potsdam.hpi.asg.logictool.mapping.SequenceBasedAndGateDecomposer.java
private boolean categoriseSequences(BDD bdd, SortedSet<IOBehaviour> sequences, List<IOBehaviour> falling, List<IOBehaviour> rising, List<IOBehaviour> constant) { for (IOBehaviour beh : sequences) { BDD startBDD = bdd;//from ww w .j ava 2 s . c om MutableBoolean resultStart = new MutableBoolean(); if (!evaluateBDD(resultStart, startBDD, beh.getStart())) { logger.error("Something went wrong"); return false; } BDD endBDD = bdd; MutableBoolean resultEnd = new MutableBoolean(); if (!evaluateBDD(resultEnd, endBDD, beh.getEnd())) { logger.error("Something went wrong"); return false; } if (resultStart.isTrue() && resultEnd.isFalse()) { falling.add(beh); //System.out.println("uups? falling?"); } else if (resultStart.isFalse() && resultEnd.isTrue()) { rising.add(beh); } else if (resultStart.isFalse() && resultEnd.isFalse()) { constant.add(beh); } else { logger.error("Const 1 should not happen"); return false; } //System.out.println(resultStart.booleanValue() + "=>" + resultEnd.booleanValue() + " : " + beh); } return true; }
From source file:com.github.jrh3k5.mojo.flume.AbstractFlumeAgentsMojoTest.java
/** * Test the building of the agent process. * //from w w w. ja v a2s . com * @throws Exception * If any errors occur during the test run. */ @Test public void testBuildAgentProcess() throws Exception { final File flumeDirectory = mock(File.class); final AgentProcess.Builder agentProcessBuilder = mock(AgentProcess.Builder.class); mockStatic(AgentProcess.class); when(AgentProcess.newBuilder(flumeDirectory)).thenReturn(agentProcessBuilder); final AgentProcess agentProcess = mock(AgentProcess.class); when(agentProcessBuilder.withAgent(agentName)).thenReturn(agentProcessBuilder); when(agentProcessBuilder.withConfigFile(configFile)).thenReturn(agentProcessBuilder); when(agentProcessBuilder.build()).thenReturn(agentProcess); final MutableBoolean copiedPlugins = new MutableBoolean(false); final MutableBoolean unpackedFlume = new MutableBoolean(false); final MutableBoolean wroteFlumeEnvironment = new MutableBoolean(false); final MutableBoolean removedLibs = new MutableBoolean(false); final MutableBoolean copiedLoggingProperties = new MutableBoolean(false); final List<Agent> passedAgents = new ArrayList<Agent>(); final ConcreteMojo toTest = setParameters(new ConcreteMojo() { @Override void copyFlumePlugins(Agent agent, File givenFlumeDirectory) throws IOException { passedAgents.add(agent); copiedPlugins.setTrue(); assertThat(givenFlumeDirectory).isEqualTo(flumeDirectory); } @Override File unpackFlume(Agent agent, FlumeArchiveCache archiveCache) throws IOException { passedAgents.add(agent); unpackedFlume.setTrue(); return flumeDirectory; } @Override void writeFlumeEnvironment(Agent agent, File givenFlumeDirectory) throws IOException { passedAgents.add(agent); wroteFlumeEnvironment.setTrue(); assertThat(givenFlumeDirectory).isEqualTo(flumeDirectory); } @Override void removeLibs(Agent agent, File givenFlumeDirectory) throws IOException { passedAgents.add(agent); removedLibs.setTrue(); assertThat(givenFlumeDirectory).isEqualTo(flumeDirectory); } @Override void copyLoggingProperties(Agent agent, File givenFlumeDirectory) throws IOException { passedAgents.add(agent); copiedLoggingProperties.setTrue(); assertThat(givenFlumeDirectory).isEqualTo(flumeDirectory); } }); assertThat(toTest.buildAgentProcess(agent)).isEqualTo(agentProcess); assertThat(copiedPlugins.isTrue()).isTrue(); assertThat(unpackedFlume.isTrue()).isTrue(); assertThat(wroteFlumeEnvironment.isTrue()).isTrue(); assertThat(passedAgents).hasSize(5).containsOnly(agent); }
From source file:com.mgmtp.perfload.agent.Transformer.java
@Override public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined, final ProtectionDomain protectionDomain, final byte[] classfileBuffer) throws IllegalClassFormatException { final String classNameWithDots = className.replace('/', '.'); EntryPoints entryPoints = config.getEntryPoints(); final Map<String, MethodInstrumentations> methodsConfig = config.getInstrumentations() .get(classNameWithDots);// w w w . ja v a2 s .c o m final boolean isFilter = entryPoints.hasFilter(classNameWithDots); final boolean isServlet = entryPoints.hasServlet(classNameWithDots); if (methodsConfig == null && !isFilter && !isServlet) { // no instrumentation configured for this class // return null, so no transformation is done return null; } logger.writeln("Transforming class: " + classNameWithDots); // flag for storing if at least one hook is weaved in final MutableBoolean weaveFlag = new MutableBoolean(); ClassReader cr = new ClassReader(classfileBuffer); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); ClassVisitor cv = new ClassVisitor(Opcodes.ASM4, cw) { @Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); if (mv != null) { if (isFilter && "doFilter".equals(name) || isServlet && "service".equals(name) && SERVLET_SERVICE_DESC.equals(desc)) { mv = createServletApiHookVisitor(access, name, desc, mv); } if (methodsConfig != null) { MethodInstrumentations methodInstrumentations = methodsConfig.get(name); if (methodInstrumentations != null) { mv = createMeasuringHookVisitor(access, name, desc, mv, methodInstrumentations); } } } return mv; } private MethodVisitor createMeasuringHookVisitor(final int access, final String methodName, final String desc, final MethodVisitor mv, final MethodInstrumentations methodInstrumentations) { boolean weave = false; if (methodInstrumentations.isEmpty()) { // no params configured, so we just weave the hook into any method with this name weave = true; } else { // weave if params match for (List<String> paramClassNames : methodInstrumentations) { Type[] argumentTypes = Type.getArgumentTypes(desc); List<String> classNames = newArrayListWithCapacity(argumentTypes.length); for (Type argumentType : argumentTypes) { classNames.add(argumentType.getClassName()); } if (classNames.equals(paramClassNames)) { weave = true; break; } } } if (weave) { logger.writeln("Instrumenting method: " + classNameWithDots + "." + methodName); weaveFlag.setValue(true); return new MeasuringHookMethodVisitor(access, classNameWithDots, methodName, desc, mv); } return mv; } private MethodVisitor createServletApiHookVisitor(final int access, final String methodName, final String desc, final MethodVisitor mv) { logger.writeln("Adding servlet api hook: " + classNameWithDots + "." + methodName); weaveFlag.setValue(true); return new ServletApiHookMethodVisitor(access, methodName, desc, mv); } }; // accept the visitor in order to perform weaving cr.accept(cv, ClassReader.EXPAND_FRAMES); if (weaveFlag.isTrue()) { byte[] transformedclassBytes = cw.toByteArray(); dumpTransformedClassFile(className, transformedclassBytes); return transformedclassBytes; } // no transformation return null; }
From source file:nl.b3p.viewer.config.services.ArcGISService.java
private void updateLayers(final ArcGISService update, final ArcGISFeatureSource linkedFS, final UpdateResult result) { /* This is a lot simpler than WMS, because layers always have an id * (name in WMS and our Layer object) *//*from w w w. jav a 2s. com*/ Map<String, Layer> updatedLayersById = new HashMap(); SimpleFeatureType ft; for (Layer updateLayer : update.layersById.values()) { MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus() .get(updateLayer.getName()); Layer updatedLayer = null; if (layerStatus == null) { // New layer ft = updateLayer.getFeatureType(); if (updateLayer.getFeatureType() != null) { if (linkedFS != null) { updateLayer.setFeatureType( linkedFS.addOrUpdateFeatureType(updateLayer.getName(), ft, new MutableBoolean())); } else { // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); } } result.getLayerStatus().put(updateLayer.getName(), new MutablePair(updateLayer, UpdateResult.Status.NEW)); updatedLayer = updateLayer; } else { assert (layerStatus.getRight() == UpdateResult.Status.MISSING); Layer old = layerStatus.getLeft(); old.setParent(null); old.update(updateLayer, additionalUpdatableDetails); layerStatus.setRight(UpdateResult.Status.UNMODIFIED); // Do not overwrite manually set feature source if (old.getFeatureType() == null || old.getFeatureType().getFeatureSource().getLinkedService() == this) { if (updateLayer.getFeatureType() == null) { // If was set before the old feature type will be removed // later when all orphan MISSING layers are removed if (old.getFeatureType() != null) { layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(null); } else { if (linkedFS != null) { MutableBoolean updated = new MutableBoolean(false); ft = linkedFS.addOrUpdateFeatureType(updateLayer.getName(), updateLayer.getFeatureType(), updated); if (old.getFeatureType() == null || updated.isTrue()) { layerStatus.setRight(UpdateResult.Status.UPDATED); } } else { ft = updateLayer.getFeatureType(); // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(ft); } } updatedLayer = old; } // will be filled in setLayerTree() updatedLayer.getChildren().clear(); updatedLayer.setParent(null); updatedLayer.setService(this); updatedLayersById.put(updateLayer.getName(), updatedLayer); } setLayerTree(getTopLayer(), updatedLayersById, update.childrenByLayerId); }
From source file:nl.b3p.viewer.config.services.ArcIMSService.java
private void updateLayers(final ArcIMSService update, final ArcXMLFeatureSource linkedFS, final UpdateResult result) { /* This is a lot simpler than WMS, because layers always have an id * (name in WMS and our Layer object) * /*from w ww . j a v a 2 s. c o m*/ * And even simpler than ArcGIS because layers have no tree structure. */ getTopLayer().getChildren().clear(); SimpleFeatureType ft; for (Layer updateLayer : update.getTopLayer().getChildren()) { MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus() .get(updateLayer.getName()); Layer updatedLayer; if (layerStatus == null) { // New layer ft = updateLayer.getFeatureType(); if (updateLayer.getFeatureType() != null) { if (linkedFS != null) { linkedFS.addOrUpdateFeatureType(updateLayer.getName(), ft, new MutableBoolean()); } else { // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); } } result.getLayerStatus().put(updateLayer.getName(), new MutablePair(updateLayer, UpdateResult.Status.NEW)); updatedLayer = updateLayer; } else { assert (layerStatus.getRight() == UpdateResult.Status.MISSING); Layer old = layerStatus.getLeft(); old.update(updateLayer); layerStatus.setRight(UpdateResult.Status.UNMODIFIED); // Do not overwrite manually set feature source if (old.getFeatureType() == null || old.getFeatureType().getFeatureSource().getLinkedService() == this) { if (updateLayer.getFeatureType() == null) { // If was set before the old feature type will be removed // later when all orphan MISSING layers are removed if (old.getFeatureType() != null) { layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(null); } else { if (linkedFS != null) { MutableBoolean updated = new MutableBoolean(false); ft = linkedFS.addOrUpdateFeatureType(updateLayer.getName(), updateLayer.getFeatureType(), updated); if (old.getFeatureType() == null || updated.isTrue()) { layerStatus.setRight(UpdateResult.Status.UPDATED); } } else { ft = updateLayer.getFeatureType(); // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(ft); } } updatedLayer = old; } assert updatedLayer.getChildren().isEmpty(); updatedLayer.setService(this); updatedLayer.setParent(getTopLayer()); getTopLayer().getChildren().add(updatedLayer); } }
From source file:nl.b3p.viewer.config.services.UpdatableFeatureSource.java
/** * Update this featuresource//w ww .j a v a 2 s. c o m */ public FeatureSourceUpdateResult update() throws Exception { final FeatureSourceUpdateResult result = new FeatureSourceUpdateResult(this); try { List<SimpleFeatureType> newFeatureTypes = this .createFeatureTypes(result.getWaitPageStatus().subtask("", 80)); //update and add the new featuretypes. for (SimpleFeatureType newFt : newFeatureTypes) { MutableBoolean updated = new MutableBoolean(); this.addOrUpdateFeatureType(newFt.getTypeName(), newFt, updated); MutablePair<SimpleFeatureType, UpdateResult.Status> ftResult = result.getFeatureTypeStatus() .get(newFt.getTypeName()); if (ftResult == null) { result.getFeatureTypeStatus().put(newFt.getTypeName(), new MutablePair(newFt, UpdateResult.Status.NEW)); } else { if (updated.isTrue()) { log.info("Feature type: " + newFt.getTypeName() + " updated"); ftResult.setRight(UpdateResult.Status.UPDATED); } else { ftResult.setRight(UpdateResult.Status.UNMODIFIED); } } } //remove featuretypes when not there Iterator<SimpleFeatureType> it = this.getFeatureTypes().iterator(); while (it.hasNext()) { SimpleFeatureType oldFt = it.next(); boolean stillExists = false; for (SimpleFeatureType newFt : newFeatureTypes) { if (newFt.getTypeName().equals(oldFt.getTypeName())) { stillExists = true; break; } } if (!stillExists) { it.remove(); } } result.setStatus(UpdateResult.Status.UPDATED); } catch (Exception e) { result.failedWithException(e); } return result; }
From source file:nl.b3p.viewer.config.services.WMSService.java
private void updateWFS(final WMSService updateWMS, final Map<String, WFSFeatureSource> linkedFSesByURL, Set<SimpleFeatureType> updatedFeatureTypes, Collection<SimpleFeatureType> outTypesToRemove, final UpdateResult result) { final Set<FeatureSource> updateFSes = getAutomaticallyLinkedFeatureSources(updateWMS.getTopLayer()); for (FeatureSource fs : updateFSes) { WFSFeatureSource oldFS = linkedFSesByURL.get(fs.getUrl()); if (oldFS == null) { log.info("Found new WFS with URL " + fs.getUrl() + " linked to WMS"); // Make available for updating layers in map, will be persisted // by cascade from Layer linkedFSesByURL.put(fs.getUrl(), (WFSFeatureSource) fs); fs.setLinkedService(this); } else {// w ww .jav a 2 s .co m log.info("Updating WFS with URL " + fs.getUrl() + " linked to WMS"); // Update or add all feature types from updated FS for (SimpleFeatureType updateFT : fs.getFeatureTypes()) { MutableBoolean updated = new MutableBoolean(); SimpleFeatureType updatedFT = oldFS.addOrUpdateFeatureType(updateFT.getTypeName(), updateFT, updated); boolean isNew = updateFT == updatedFT; if (updated.isTrue()) { updatedFeatureTypes.add(updatedFT); } if (isNew) { log.info("New feature type in WFS: " + updateFT.getTypeName()); } } // Find feature types which do not exist in updated FS // Remove these later on- // Set<SimpleFeatureType> typesToRemove = new HashSet(); for (SimpleFeatureType oldFT : oldFS.getFeatureTypes()) { if (fs.getFeatureType(oldFT.getTypeName()) == null) { // Don'tnot modify list which we are iterating on typesToRemove.add(oldFT); log.info("Feature type " + oldFT.getTypeName() + " does no longer exist"); } } outTypesToRemove.addAll(typesToRemove); } } }
From source file:org.pircbotx.hooks.ListenerAdapterTest.java
@Test(description = "Do an actual test with a sample ListenerAdapter") public void usabilityTest() throws Exception { final MutableBoolean onMessageCalled = new MutableBoolean(false); final MutableBoolean onGenericMessageCalled = new MutableBoolean(false); ListenerAdapter testListener = new ListenerAdapter() { @Override/*from www .j a va 2s .c o m*/ public void onMessage(MessageEvent event) throws Exception { onMessageCalled.setValue(true); } @Override public void onGenericMessage(GenericMessageEvent event) throws Exception { onGenericMessageCalled.setValue(true); } }; testListener.onEvent(mock(MessageEvent.class)); assertTrue(onMessageCalled.isTrue(), "onMessage wasn't called on MessageEvent"); assertTrue(onGenericMessageCalled.isTrue(), "onGenericMessage wasn't called on MessageEvent"); }