Search in sources :

Example 46 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.

the class GBPTreeConsistencyCheckerTestBase method assertReportUnusedPage.

private static <KEY, VALUE> void assertReportUnusedPage(GBPTree<KEY, VALUE> index, long targetNode) throws IOException {
    MutableBoolean called = new MutableBoolean();
    index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {

        @Override
        public void unusedPage(long pageId, Path file) {
            called.setTrue();
            assertEquals(targetNode, pageId);
        }
    }, NULL);
    assertCalled(called);
}
Also used : Path(java.nio.file.Path) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Example 47 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.

the class GBPTreeConsistencyCheckerTestBase method assertReportPointerToOldVersionOfTreeNode.

private static <KEY, VALUE> void assertReportPointerToOldVersionOfTreeNode(GBPTree<KEY, VALUE> index, long targetNode) throws IOException {
    MutableBoolean called = new MutableBoolean();
    index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {

        @Override
        public void pointerToOldVersionOfTreeNode(long pageId, long successorPointer, Path file) {
            called.setTrue();
            assertEquals(targetNode, pageId);
            assertEquals(GenerationSafePointer.MAX_POINTER, successorPointer);
        }
    }, NULL);
    assertCalled(called);
}
Also used : Path(java.nio.file.Path) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Example 48 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project flink by apache.

the class HiveParserUtils method rewriteGroupingFunctionAST.

public static HiveParserASTNode rewriteGroupingFunctionAST(final List<HiveParserASTNode> grpByAstExprs, HiveParserASTNode targetNode, final boolean noneSet) throws SemanticException {
    final MutableBoolean visited = new MutableBoolean(false);
    final MutableBoolean found = new MutableBoolean(false);
    final boolean legacyGrouping = legacyGrouping();
    TreeVisitorAction action = new TreeVisitorAction() {

        @Override
        public Object pre(Object t) {
            return t;
        }

        @Override
        public Object post(Object t) {
            HiveParserASTNode current = (HiveParserASTNode) t;
            // rewrite grouping function
            if (current.getType() == HiveASTParser.TOK_FUNCTION && current.getChildCount() >= 2) {
                HiveParserASTNode func = (HiveParserASTNode) current.getChild(0);
                if (func.getText().equals("grouping")) {
                    visited.setValue(true);
                    convertGrouping(current, grpByAstExprs, noneSet, legacyGrouping, found);
                }
            } else if (legacyGrouping && current.getType() == HiveASTParser.TOK_TABLE_OR_COL && current.getChildCount() == 1) {
                // rewrite grouping__id
                HiveParserASTNode child = (HiveParserASTNode) current.getChild(0);
                if (child.getText().equalsIgnoreCase(VirtualColumn.GROUPINGID.getName())) {
                    return convertToLegacyGroupingId(current, grpByAstExprs.size());
                }
            }
            return t;
        }
    };
    HiveParserASTNode newTargetNode = (HiveParserASTNode) new TreeVisitor(HiveASTParseDriver.ADAPTOR).visit(targetNode, action);
    if (visited.booleanValue() && !found.booleanValue()) {
        throw new SemanticException("Expression in GROUPING function not present in GROUP BY");
    }
    return newTargetNode;
}
Also used : TreeVisitor(org.antlr.runtime.tree.TreeVisitor) HiveParserASTNode(org.apache.flink.table.planner.delegation.hive.copy.HiveParserASTNode) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) TreeVisitorAction(org.antlr.runtime.tree.TreeVisitorAction) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 49 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project flink by apache.

the class KinesisDataFetcherTest method testPeriodicWatermark.

@Test
public void testPeriodicWatermark() {
    final MutableLong clock = new MutableLong();
    final MutableBoolean isTemporaryIdle = new MutableBoolean();
    final List<Watermark> watermarks = new ArrayList<>();
    String fakeStream1 = "fakeStream1";
    StreamShardHandle shardHandle = new StreamShardHandle(fakeStream1, new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0)));
    TestSourceContext<String> sourceContext = new TestSourceContext<String>() {

        @Override
        public void emitWatermark(Watermark mark) {
            watermarks.add(mark);
        }

        @Override
        public void markAsTemporarilyIdle() {
            isTemporaryIdle.setTrue();
        }
    };
    HashMap<String, String> subscribedStreamsToLastSeenShardIdsUnderTest = new HashMap<>();
    final KinesisDataFetcher<String> fetcher = new TestableKinesisDataFetcher<String>(singletonList(fakeStream1), sourceContext, new java.util.Properties(), new KinesisDeserializationSchemaWrapper<>(new org.apache.flink.streaming.util.serialization.SimpleStringSchema()), 1, 1, new AtomicReference<>(), new LinkedList<>(), subscribedStreamsToLastSeenShardIdsUnderTest, FakeKinesisBehavioursFactory.nonReshardedStreamsBehaviour(new HashMap<>())) {

        @Override
        protected long getCurrentTimeMillis() {
            return clock.getValue();
        }
    };
    Whitebox.setInternalState(fetcher, "periodicWatermarkAssigner", watermarkAssigner);
    SequenceNumber seq = new SequenceNumber("fakeSequenceNumber");
    // register shards to subsequently emit records
    int shardIndex = fetcher.registerNewSubscribedShardState(new KinesisStreamShardState(KinesisDataFetcher.convertToStreamShardMetadata(shardHandle), shardHandle, seq));
    StreamRecord<String> record1 = new StreamRecord<>(String.valueOf(Long.MIN_VALUE), Long.MIN_VALUE);
    fetcher.emitRecordAndUpdateState(record1.getValue(), record1.getTimestamp(), shardIndex, seq);
    Assert.assertEquals(record1, sourceContext.getCollectedOutputs().poll());
    fetcher.emitWatermark();
    Assert.assertTrue("potential watermark equals previous watermark", watermarks.isEmpty());
    StreamRecord<String> record2 = new StreamRecord<>(String.valueOf(1), 1);
    fetcher.emitRecordAndUpdateState(record2.getValue(), record2.getTimestamp(), shardIndex, seq);
    Assert.assertEquals(record2, sourceContext.getCollectedOutputs().poll());
    fetcher.emitWatermark();
    Assert.assertFalse("watermark advanced", watermarks.isEmpty());
    Assert.assertEquals(new Watermark(record2.getTimestamp()), watermarks.remove(0));
    Assert.assertFalse("not idle", isTemporaryIdle.booleanValue());
    // test idle timeout
    long idleTimeout = 10;
    // advance clock idleTimeout
    clock.add(idleTimeout + 1);
    fetcher.emitWatermark();
    Assert.assertFalse("not idle", isTemporaryIdle.booleanValue());
    Assert.assertTrue("not idle, no new watermark", watermarks.isEmpty());
    // activate idle timeout
    Whitebox.setInternalState(fetcher, "shardIdleIntervalMillis", idleTimeout);
    fetcher.emitWatermark();
    Assert.assertTrue("idle", isTemporaryIdle.booleanValue());
    Assert.assertTrue("idle, no watermark", watermarks.isEmpty());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TestSourceContext(org.apache.flink.streaming.connectors.kinesis.testutils.TestSourceContext) StreamShardHandle(org.apache.flink.streaming.connectors.kinesis.model.StreamShardHandle) SequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber) TestableKinesisDataFetcher(org.apache.flink.streaming.connectors.kinesis.testutils.TestableKinesisDataFetcher) Properties(java.util.Properties) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) MutableLong(org.apache.commons.lang3.mutable.MutableLong) SimpleStringSchema(org.apache.flink.api.common.serialization.SimpleStringSchema) KinesisStreamShardState(org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShardState) Shard(com.amazonaws.services.kinesis.model.Shard) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test)

Example 50 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project zaproxy by zaproxy.

the class ExtensionAutoUpdate method installNewExtensions.

public void installNewExtensions() {
    final OptionsParamCheckForUpdates options = getModel().getOptionsParam().getCheckForUpdatesParam();
    List<Downloader> handledFiles = new ArrayList<>();
    MutableBoolean allInstalled = new MutableBoolean(true);
    for (Downloader dl : downloadFiles) {
        if (dl.getFinished() == null) {
            continue;
        }
        handledFiles.add(dl);
        try {
            if (!dl.isValidated()) {
                logger.debug("Ignoring unvalidated download: {}", dl.getUrl());
                allInstalled.setFalse();
                if (addonsDialog != null) {
                    addonsDialog.notifyAddOnDownloadFailed(dl.getUrl().toString());
                } else {
                    String url = dl.getUrl().toString();
                    for (AddOn addOn : latestVersionInfo.getAddOns()) {
                        if (url.equals(addOn.getUrl().toString())) {
                            addOn.setInstallationStatus(AddOn.InstallationStatus.AVAILABLE);
                            break;
                        }
                    }
                }
            } else if (AddOn.isAddOnFileName(dl.getTargetFile().getName())) {
                File f = dl.getTargetFile();
                if (!options.getDownloadDirectory().equals(dl.getTargetFile().getParentFile())) {
                    // add-ons
                    try {
                        f = new File(options.getDownloadDirectory(), dl.getTargetFile().getName());
                        logger.info("Moving downloaded add-on from {} to {}", dl.getTargetFile().getAbsolutePath(), f.getAbsolutePath());
                        FileUtils.moveFile(dl.getTargetFile(), f);
                    } catch (Exception e) {
                        if (!f.exists() && dl.getTargetFile().exists()) {
                            logger.error("Failed to move downloaded add-on from {} to {} - left at original location", dl.getTargetFile().getAbsolutePath(), f.getAbsolutePath(), e);
                            f = dl.getTargetFile();
                        } else {
                            logger.error("Failed to move downloaded add-on from {} to {} - skipping", dl.getTargetFile().getAbsolutePath(), f.getAbsolutePath(), e);
                            allInstalled.setFalse();
                            continue;
                        }
                    }
                }
                AddOn.createAddOn(f.toPath()).ifPresent(ao -> {
                    if (ao.canLoadInCurrentVersion()) {
                        allInstalled.setValue(allInstalled.booleanValue() & install(ao));
                    } else {
                        logger.info("Can't load add-on: {} Not before={} Not from={} Version={}", ao.getName(), ao.getNotBeforeVersion(), ao.getNotFromVersion(), Constant.PROGRAM_VERSION);
                    }
                });
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
    for (Downloader dl : handledFiles) {
        // Can't remove in loop above as we're iterating through the list
        this.downloadFiles.remove(dl);
    }
    this.installsCompleted = true;
    this.installsOk = allInstalled.booleanValue();
}
Also used : ExtensionAdaptor(org.parosproxy.paros.extension.ExtensionAdaptor) Model(org.parosproxy.paros.model.Model) URL(java.net.URL) Date(java.util.Date) FileCopier(org.parosproxy.paros.model.FileCopier) ExtensionFactory(org.zaproxy.zap.control.ExtensionFactory) Vector(java.util.Vector) AddOnRunRequirements(org.zaproxy.zap.control.AddOn.AddOnRunRequirements) AddOnUninstallListener(org.zaproxy.zap.extension.autoupdate.UninstallationProgressDialogue.AddOnUninstallListener) SwingWorker(javax.swing.SwingWorker) Constant(org.parosproxy.paros.Constant) JFileChooser(javax.swing.JFileChooser) Extension(org.parosproxy.paros.extension.Extension) ExtensionHook(org.parosproxy.paros.extension.ExtensionHook) Path(java.nio.file.Path) Platform(org.zaproxy.zap.control.AddOnCollection.Platform) AddOnUninstallationProgressCallback(org.zaproxy.zap.control.AddOnUninstallationProgressCallback) ZAP(org.zaproxy.zap.ZAP) AddOn(org.zaproxy.zap.control.AddOn) Collection(java.util.Collection) Set(java.util.Set) KeyEvent(java.awt.event.KeyEvent) Control(org.parosproxy.paros.control.Control) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) Logger(org.apache.logging.log4j.Logger) JCheckBox(javax.swing.JCheckBox) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) UninstallationProgressEvent(org.zaproxy.zap.extension.autoupdate.UninstallationProgressDialogue.UninstallationProgressEvent) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) ZapMenuItem(org.zaproxy.zap.view.ZapMenuItem) CommandLine(org.parosproxy.paros.CommandLine) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CommandLineArgument(org.parosproxy.paros.extension.CommandLineArgument) ZapRelease(org.zaproxy.zap.control.ZapRelease) UninstallationResult(org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.UninstallationResult) ImageIcon(javax.swing.ImageIcon) CommandLineListener(org.parosproxy.paros.extension.CommandLineListener) ScanStatus(org.zaproxy.zap.view.ScanStatus) EventQueue(java.awt.EventQueue) AddOnChangesResult(org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.AddOnChangesResult) XMLPropertiesConfiguration(org.apache.commons.configuration.XMLPropertiesConfiguration) JButton(javax.swing.JButton) Iterator(java.util.Iterator) UninstallationProgressHandler(org.zaproxy.zap.extension.autoupdate.UninstallationProgressDialogue.UninstallationProgressHandler) Files(java.nio.file.Files) Window(java.awt.Window) AddOnCollection(org.zaproxy.zap.control.AddOnCollection) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) AddOnRunIssuesUtils(org.zaproxy.zap.control.AddOnRunIssuesUtils) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) JOptionPane(javax.swing.JOptionPane) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) View(org.parosproxy.paros.view.View) AddOn(org.zaproxy.zap.control.AddOn) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) ArrayList(java.util.ArrayList) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Aggregations

MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)107 Test (org.junit.Test)28 Path (java.nio.file.Path)26 Test (org.junit.jupiter.api.Test)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)12 Query (org.apache.apex.malhar.lib.appdata.schemas.Query)11 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)11 List (java.util.List)9 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)8 MutableInt (org.apache.commons.lang3.mutable.MutableInt)7 MutableLong (org.apache.commons.lang3.mutable.MutableLong)7 Collections (java.util.Collections)6 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)6 Set (java.util.Set)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 PageCache (org.neo4j.io.pagecache.PageCache)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ClassAd (org.apache.asterix.external.classad.ClassAd)4