List of usage examples for org.apache.commons.lang3.mutable MutableBoolean MutableBoolean
public MutableBoolean(final Boolean value)
From source file:com.mirth.connect.plugins.datapruner.DataPrunerPanel.java
public void doStart() { final MutableBoolean saveChanges = new MutableBoolean(false); if (isSaveEnabled()) { if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, "Settings changes must be saved first, would you like to save the settings and prune now?", "Select an Option", JOptionPane.OK_CANCEL_OPTION)) { if (!validateFields()) { return; }//from w w w . j a v a 2s . com saveChanges.setValue(true); } else { return; } } setStartTaskVisible(false); final String workingId = parent.startWorking("Starting the data pruner..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() { if (saveChanges.getValue()) { try { plugin.setPropertiesToServer(getProperties()); } catch (Exception e) { getFrame().alertThrowable(getFrame(), e); return null; } } try { parent.mirthClient.getServlet(DataPrunerServletInterface.class).start(); } catch (Exception e) { parent.alertThrowable(parent, e, "An error occurred while attempting to start the data pruner."); return null; } return null; } @Override public void done() { if (saveChanges.getValue()) { setSaveEnabled(false); } parent.stopWorking(workingId); updateStatus(); } }; worker.execute(); }
From source file:com.datatorrent.lib.appdata.query.SimpleDoneQueryQueueManagerTest.java
@Test public void expiredTestBlockingValidFirstExpiredLast() throws Exception { SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>(); sdqqm.setup(null);//from w w w. j a v a 2 s . co m sdqqm.beginWindow(0); Query query = new MockQuery("1"); MutableBoolean queueContext = new MutableBoolean(false); sdqqm.enqueue(query, null, queueContext); Query query1 = new MockQuery("2"); MutableBoolean queueContext1 = new MutableBoolean(false); sdqqm.enqueue(query1, null, queueContext1); Assert.assertEquals(2, sdqqm.getNumLeft()); Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft()); QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock(); Assert.assertEquals(1, sdqqm.getNumLeft()); Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft()); sdqqm.endWindow(); sdqqm.beginWindow(1); Assert.assertEquals(2, sdqqm.getNumLeft()); Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft()); queueContext1.setValue(true); qb = sdqqm.dequeueBlock(); Assert.assertEquals(1, sdqqm.getNumLeft()); Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft()); testBlocking(sdqqm); Assert.assertEquals(0, sdqqm.getNumLeft()); Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft()); sdqqm.endWindow(); sdqqm.beginWindow(2); Assert.assertEquals(1, sdqqm.getNumLeft()); Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft()); qb = sdqqm.dequeueBlock(); testBlocking(sdqqm); sdqqm.endWindow(); sdqqm.teardown(); }
From source file:fr.duminy.jbackup.core.JBackupImplTest.java
@Test public void testRestore_withCancellable() throws Throwable { // prepare test final Path archive = tempFolder.newFolder().toPath().resolve("archive.zip"); final Path targetDirectory = tempFolder.newFolder().toPath(); final BackupConfiguration config = createConfiguration(); final MutableBoolean taskStarted = new MutableBoolean(false); final Task mockRestoreTask = createAlwaysWaitingTask(Task.class, taskStarted); final MutableObject<Cancellable> actualCancellable = new MutableObject<>(); final MutableObject<TaskListener> actualListener = new MutableObject<>(); JBackupImpl jBackup = spy(new JBackupImpl() { @Override/*from w w w .j a v a 2s.c o m*/ Task createRestoreTask(BackupConfiguration config, Path archive, Path targetDirectory, TaskListener listener, Cancellable cancellable) { actualListener.setValue(listener); actualCancellable.setValue(cancellable); return mockRestoreTask; } }); // test try { Future<Void> future = jBackup.restore(config, archive, targetDirectory); // wait task is actually started waitTaskStarted(taskStarted, actualCancellable); assertThat(actualCancellable.getValue()).as("cancellable").isNotNull(); assertThat(actualCancellable.getValue().isCancelled()).as("cancelled").isFalse(); future.cancel(true); assertThat(actualCancellable.getValue().isCancelled()).as("cancelled").isTrue(); } finally { jBackup.shutdown(null); } // assertions InOrder inOrder = inOrder(mockRestoreTask, jBackup); inOrder.verify(jBackup, times(1)).restore(eq(config), eq(archive), eq(targetDirectory)); // called above inOrder.verify(jBackup, times(1)).createRestoreTask(eq(config), eq(archive), eq(targetDirectory), eq(actualListener.getValue()), eq(actualCancellable.getValue())); inOrder.verify(mockRestoreTask, times(1)).call(); inOrder.verify(jBackup, times(1)).shutdown(isNull(TerminationListener.class)); // called above inOrder.verifyNoMoreInteractions(); }
From source file:asterix.parser.classad.AttributeReference.java
public boolean privateEvaluate(EvalState state, Value val, ExprTreeHolder sig) throws HyracksDataException { ExprTreeHolder tree = new ExprTreeHolder(); ExprTreeHolder exprSig = new ExprTreeHolder(); ClassAd curAd = new ClassAd(state.getCurAd()); MutableBoolean rval = new MutableBoolean(true); switch (findExpr(state, tree, exprSig, true)) { case EVAL_FAIL: rval.setValue(false);/*from w w w . j ava2s .com*/ break; case EVAL_ERROR: val.setErrorValue(); break; case EVAL_UNDEF: val.setUndefinedValue(); break; case EVAL_OK: { if (state.getDepthRemaining() <= 0) { val.setErrorValue(); state.getCurAd().setValue(curAd); return false; } state.decrementDepth(); rval.setValue(tree.publicEvaluate(state, val)); state.incrementDepth(); break; } default: throw new HyracksDataException("ClassAd: Should not reach here"); } sig.setInnerTree((new AttributeReference(exprSig, attributeStr, absolute))); state.getCurAd().setValue(curAd); return rval.booleanValue(); }
From source file:com.datatorrent.lib.appdata.query.SimpleDoneQueryQueueManagerTest.java
@Test public void simpleExpire1ThenBlock() { SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>(); sdqqm.setup(null);// ww w . ja v a 2s. c o m sdqqm.beginWindow(0); Query query = new MockQuery("1"); sdqqm.enqueue(query, null, new MutableBoolean(false)); QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeue(); Assert.assertEquals("Should return same query.", query, qb.getQuery()); qb.getQueueContext().setValue(true); qb = sdqqm.dequeue(); Assert.assertEquals("Should return back null.", null, qb); sdqqm.endWindow(); sdqqm.beginWindow(1); qb = sdqqm.dequeue(); Assert.assertEquals("Should return back null.", null, qb); sdqqm.endWindow(); sdqqm.teardown(); }
From source file:com.datatorrent.lib.appdata.query.SimpleDoneQueryQueueManagerTest.java
@Test public void simpleExpireBlockThenUnblock() throws Exception { SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>(); sdqqm.setup(null);/*from w ww .j a v a2 s . c o m*/ sdqqm.beginWindow(0); Query query = new MockQuery("1"); MutableBoolean expire = new MutableBoolean(false); sdqqm.enqueue(query, null, expire); sdqqm.endWindow(); sdqqm.beginWindow(1); //Expire expire.setValue(true); ExceptionSaverExceptionHandler eseh = new ExceptionSaverExceptionHandler(); testBlockingNoStop(sdqqm, eseh); query = new MockQuery("2"); sdqqm.enqueue(query, null, new MutableBoolean(false)); Thread.sleep(1000); Assert.assertNull(eseh.getCaughtThrowable()); sdqqm.endWindow(); sdqqm.teardown(); }
From source file:com.ibm.jaggr.core.impl.modulebuilder.javascript.RequireExpansionCompilerPassTest.java
@Test public void testArrayMutation() throws Exception { String code = "define([\"module\"],function(bar){require([\"foo\", \"abc\", \"bcd\", \"cde\", \"def\", \"efg\", \"fgh\", \"ghi\"]);});"; JSSourceFile sf = JSSourceFile.fromCode("test", code); List<JSSourceFile> sources = new ArrayList<JSSourceFile>(); sources.add(sf);/* w w w . java2 s .c o m*/ Compiler compiler = new Compiler(); CompilerOptions compiler_options = new CompilerOptions(); CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(compiler_options); compiler.compile(externs, sources, compiler_options); String output = compiler.toSource(); System.out.println(output); // verfiy that array mutation occurs Assert.assertTrue(output.endsWith("fgh ghi\".split(\" \"))});")); List<ModuleDeps> expanded = new ArrayList<ModuleDeps>(); RequireExpansionCompilerPass pass = new RequireExpansionCompilerPass(mockAggregator, new Features(), null, expanded, new MutableBoolean(false), true, null, false, null); compiler = new Compiler(); compiler_options = new CompilerOptions(); CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(compiler_options); compiler_options.customPasses = HashMultimap.create(); compiler_options.customPasses.put(CustomPassExecutionTime.BEFORE_CHECKS, pass); compiler.compile(externs, sources, compiler_options); output = compiler.toSource(); System.out.println(output); // Verify that array mutation doesn't occur Assert.assertFalse(output.contains(".split(")); Assert.assertTrue(output.endsWith("\"ghi\",\"" + placeHolder0 + "\"])});")); }
From source file:asterix.parser.classad.Operation.java
public static int privateDoOperation(int op, Value val1, Value val2, Value val3, boolean valid1, boolean valid2, boolean valid3, Value result, EvalState es) throws HyracksDataException { ValueType vt1;//from www. jav a2 s . c o m ValueType vt2; ValueType vt3; // get the types of the values vt1 = val1.getType(); vt2 = val2.getType(); vt3 = val3.getType(); // take care of the easy cases if (op == OpKind_NO_OP || op == OpKind_PARENTHESES_OP) { result.copyFrom(val1); return SigValues.SIG_CHLD1.ordinal(); } else if (op == OpKind_UNARY_PLUS_OP) { if (vt1 == ValueType.BOOLEAN_VALUE || vt1 == ValueType.STRING_VALUE || val1.isListValue() || vt1 == ValueType.CLASSAD_VALUE || vt1 == ValueType.ABSOLUTE_TIME_VALUE) { result.setErrorValue(); } else { // applies for ERROR, UNDEFINED and Numbers result.copyFrom(val1); } return SigValues.SIG_CHLD1.ordinal(); } // test for cases when evaluation is strict if (isStrictOperator(op)) { // check for error values if (vt1 == ValueType.ERROR_VALUE) { result.setErrorValue(); return SigValues.SIG_CHLD1.ordinal(); } if (valid2 && vt2 == ValueType.ERROR_VALUE) { result.setErrorValue(); return SigValues.SIG_CHLD2.ordinal(); } if (valid3 && vt3 == ValueType.ERROR_VALUE) { result.setErrorValue(); return SigValues.SIG_CHLD3.ordinal(); } // check for undefined values. we need to check if the corresponding // tree exists, because these values would be undefined" anyway then. if (valid1 && vt1 == ValueType.UNDEFINED_VALUE) { result.setUndefinedValue(); return SigValues.SIG_CHLD1.ordinal(); } if (valid2 && vt2 == ValueType.UNDEFINED_VALUE) { result.setUndefinedValue(); return SigValues.SIG_CHLD2.ordinal(); } if (valid3 && vt3 == ValueType.UNDEFINED_VALUE) { result.setUndefinedValue(); return SigValues.SIG_CHLD3.ordinal(); } } // comparison operations (binary, one unary) if (op >= OpKind_COMPARISON_START && op <= OpKind_COMPARISON_END) { return (doComparison(op, val1, val2, result)); } // arithmetic operations (binary) if (op >= OpKind_ARITHMETIC_START && op <= OpKind_ARITHMETIC_END) { return (doArithmetic(op, val1, val2, result)); } // logical operators (binary, one unary) if (op >= OpKind_LOGIC_START && op <= OpKind_LOGIC_END) { return (doLogical(op, val1, val2, result)); } // bitwise operators (binary, one unary) if (op >= OpKind_BITWISE_START && op <= OpKind_BITWISE_END) { return (doBitwise(op, val1, val2, result)); } // misc. if (op == OpKind_TERNARY_OP) { // ternary (if-operator) MutableBoolean b = new MutableBoolean(false); // if the selector is UNDEFINED, the result is undefined if (vt1 == ValueType.UNDEFINED_VALUE) { result.setUndefinedValue(); return SigValues.SIG_CHLD1.ordinal(); } if (!val1.isBooleanValueEquiv(b)) { result.setErrorValue(); return SigValues.SIG_CHLD1.ordinal(); } else if (b.booleanValue()) { result.copyFrom(val2); return (SigValues.SIG_CHLD2.ordinal()); } else { result.copyFrom(val3); return (SigValues.SIG_CHLD3.ordinal()); } } else if (op == OpKind_SUBSCRIPT_OP) { // subscripting from a list (strict) if (vt1 == ValueType.CLASSAD_VALUE && vt2 == ValueType.STRING_VALUE) { ClassAd classad = new ClassAd(); AMutableCharArrayString index = new AMutableCharArrayString(); val1.isClassAdValue(classad); val2.isStringValue(index); if (classad.lookup(index.toString()) == null) { result.setErrorValue(); return SigValues.SIG_CHLD2.ordinal(); } if (!classad.evaluateAttr(index.toString(), result)) { result.setErrorValue(); return SigValues.SIG_CHLD2.ordinal(); } return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); } else if (val1.isListValue() && vt2 == ValueType.INTEGER_VALUE) { AMutableInt64 index = new AMutableInt64(0); ExprList elist = new ExprList(); val1.isListValue(elist); val2.isIntegerValue(index); // check bounds if (index.getLongValue() < 0 || index.getLongValue() >= elist.getExprList().size()) { result.setErrorValue(); return SigValues.SIG_CHLD2.ordinal(); } // get value elist.getValue(result, elist.get((int) index.getLongValue()), es); return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); } // should not reach here throw new HyracksDataException("Should not get here"); } return -1; }
From source file:com.ibm.jaggr.core.impl.cache.GzipCacheImplTest.java
@SuppressWarnings("unchecked") @Test//ww w . ja v a 2 s . co m 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:com.ibm.jaggr.core.impl.modulebuilder.javascript.RequireExpansionCompilerPassTest.java
@Test public void testRequireDepsExpansion() throws Exception { List<ModuleDeps> expanded = new ArrayList<ModuleDeps>(); RequireExpansionCompilerPass pass = new RequireExpansionCompilerPass(mockAggregator, new Features(), null, expanded, new MutableBoolean(false), true, null, false, null); String code, output;/*from w w w . j a v a 2s.c om*/ // Ensure dependency list is modified for the following code = "require = { deps:[\"foo\"] };"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("require={deps:[\"foo\",\"" + placeHolder0 + "\"]};", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); code = "require.deps = [\"foo\"];"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("require.deps=[\"foo\",\"" + placeHolder0 + "\"];", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); code = "this.require.deps = [\"foo\"];"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("this.require.deps=[\"foo\",\"" + placeHolder0 + "\"];", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); code = "obj.require.deps = [\"foo\"];"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("obj.require.deps=[\"foo\",\"" + placeHolder0 + "\"];", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); code = "this.require = {deps:[\"foo\"]};"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("this.require={deps:[\"foo\",\"" + placeHolder0 + "\"]};", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); code = "obj.require = {deps:[\"foo\"]};"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("obj.require={deps:[\"foo\",\"" + placeHolder0 + "\"]};", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); code = "var require = {deps:[\"foo\"]};"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("var require={deps:[\"foo\",\"" + placeHolder0 + "\"]};", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); code = "obj = {require: {deps: [\"foo\"]}};"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("obj={require:{deps:[\"foo\",\"" + placeHolder0 + "\"]}};", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); code = "var obj = {require: {deps:[\"foo\"]}};"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("var obj={require:{deps:[\"foo\",\"" + placeHolder0 + "\"]}};", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); code = "call({require: {deps:[\"foo\"]}});"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("call({require:{deps:[\"foo\",\"" + placeHolder0 + "\"]}});", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); // Negative tests. Dependency list should not be modified code = "deps = [\"foo\"];"; output = runPass(pass, code); System.out.println(output); Assert.assertTrue(output.contains("[\"foo\"]")); code = "this.deps = [\"foo\"];"; output = runPass(pass, code); System.out.println(output); Assert.assertTrue(output.contains("[\"foo\"]")); code = "var obj = {deps:[\"foo\"]};"; output = runPass(pass, code); System.out.println(output); Assert.assertTrue(output.contains("[\"foo\"]")); code = "var obj = {top: {deps:[\"foo\"]}};"; output = runPass(pass, code); System.out.println(output); Assert.assertTrue(output.contains("[\"foo\"]")); code = "call({obj: {deps:[\"foo\"]}});"; output = runPass(pass, code); System.out.println(output); Assert.assertTrue(output.contains("[\"foo\"]")); code = "require.deps=deps;"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals(code, output); code = "require.deps={\"foo\":0};"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals(code, output); // ensure proper placement of expanded deps code = "require.deps=[first,\"foo\",third];"; output = runPass(pass, code); System.out.println(output); Assert.assertEquals("require.deps=[first,\"foo\",third,\"" + placeHolder0 + "\"];", output); Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })), expanded.get(0).getModuleIds()); }