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);
}
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);
}
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;
}
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());
}
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();
}
Aggregations