use of java.util.function.Predicate in project hibernate-orm by hibernate.
the class AbstractFunctionalTest method expectPutWithValue.
protected CountDownLatch expectPutWithValue(AdvancedCache cache, Predicate<Object> valuePredicate, int numUpdates) {
if (!cacheMode.isInvalidation() && accessType != AccessType.NONSTRICT_READ_WRITE) {
CountDownLatch latch = new CountDownLatch(numUpdates);
ExpectingInterceptor.get(cache).when((ctx, cmd) -> cmd instanceof PutKeyValueCommand && valuePredicate.test(((PutKeyValueCommand) cmd).getValue())).countDown(latch);
cleanup.add(() -> ExpectingInterceptor.cleanup(cache));
return latch;
} else {
return new CountDownLatch(0);
}
}
use of java.util.function.Predicate in project jersey by jersey.
the class ProviderBinder method bindProviders.
/**
* Bind all providers contained in {@code p roviderBag} (classes and instances) using injection manager. Configuration is
* also committed.
*
* @param componentBag bag of provider classes and instances.
* @param constrainedTo current runtime (client or server).
* @param registeredClasses classes which are manually registered by the user (not found by the classpath scanning).
* @param injectionManager injection manager the binder will use to bind the providers into.
*/
public static void bindProviders(ComponentBag componentBag, RuntimeType constrainedTo, Set<Class<?>> registeredClasses, InjectionManager injectionManager) {
Predicate<ContractProvider> filter = ComponentBag.EXCLUDE_EMPTY.and(ComponentBag.excludeMetaProviders(injectionManager));
/*
* Check the {@code component} whether it is correctly configured for client or server {@link RuntimeType runtime}.
*/
Predicate<Class<?>> correctlyConfigured = componentClass -> Providers.checkProviderRuntime(componentClass, componentBag.getModel(componentClass), constrainedTo, registeredClasses == null || !registeredClasses.contains(componentClass), false);
/*
* These binder will be register to Bean Manager at the and of method because of a bulk registration to avoid register
* each binder alone.
*/
Collection<Binder> binderToRegister = new ArrayList<>();
// Bind provider classes except for pure meta-providers and providers with empty contract models (e.g. resources)
Set<Class<?>> classes = new LinkedHashSet<>(componentBag.getClasses(filter));
if (constrainedTo != null) {
classes = classes.stream().filter(correctlyConfigured).collect(Collectors.toSet());
}
for (final Class<?> providerClass : classes) {
final ContractProvider model = componentBag.getModel(providerClass);
binderToRegister.addAll(createProviderBinders(providerClass, model));
}
// Bind pure provider instances except for pure meta-providers and providers with empty contract models (e.g. resources)
Set<Object> instances = componentBag.getInstances(filter);
if (constrainedTo != null) {
instances = instances.stream().filter(component -> correctlyConfigured.test(component.getClass())).collect(Collectors.toSet());
}
for (final Object provider : instances) {
final ContractProvider model = componentBag.getModel(provider.getClass());
binderToRegister.addAll(createProviderBinders(provider, model));
}
injectionManager.register(CompositeBinder.wrap(binderToRegister));
}
use of java.util.function.Predicate in project neo4j by neo4j.
the class TestShortestPath method withFilters.
@Test
public void withFilters() throws Exception {
// Layout:
//
// (a)-->(b)-->(c)-->(d)
// \ ^
// -->(g)-->(h)--/
//
graph.makeEdgeChain("a,b,c,d");
graph.makeEdgeChain("a,g,h,d");
final Node a = graph.getNode("a");
final Node d = graph.getNode("d");
final Node b = graph.getNode("b");
b.setProperty("skip", true);
final Predicate<Node> filter = item -> {
final boolean skip = (Boolean) item.getProperty("skip", false);
return !skip;
};
testShortestPathFinder(finder -> assertPaths(finder.findAllPaths(a, d), "a,g,h,d"), ((StandardExpander) PathExpanders.allTypesAndDirections()).addNodeFilter(filter), 10);
}
use of java.util.function.Predicate in project neo4j by neo4j.
the class StoreMigrator method moveMigratedFiles.
@Override
public void moveMigratedFiles(File migrationDir, File storeDir, String versionToUpgradeFrom, String versionToUpgradeTo) throws IOException {
// Move the migrated ones into the store directory
StoreFile.fileOperation(MOVE, fileSystem, migrationDir, storeDir, StoreFile.currentStoreFiles(), // allow to skip non existent source files
true, // allow to overwrite target files
ExistingTargetStrategy.OVERWRITE, StoreFileType.values());
// move the files with the page cache.
try {
Iterable<FileHandle> fileHandles = pageCache.streamFilesRecursive(migrationDir)::iterator;
for (FileHandle fh : fileHandles) {
Predicate<StoreFile> predicate = storeFile -> storeFile.fileName(StoreFileType.STORE).equals(fh.getFile().getName());
if (StreamSupport.stream(StoreFile.currentStoreFiles().spliterator(), false).anyMatch(predicate)) {
final Optional<PagedFile> optionalPagedFile = pageCache.getExistingMapping(fh.getFile());
if (optionalPagedFile.isPresent()) {
optionalPagedFile.get().close();
}
fh.rename(new File(storeDir, fh.getFile().getName()), StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (NoSuchFileException e) {
//This means that we had no files only present in the page cache, this is fine.
}
RecordFormats oldFormat = selectForVersion(versionToUpgradeFrom);
RecordFormats newFormat = selectForVersion(versionToUpgradeTo);
boolean movingAwayFromVersionTrailers = oldFormat.hasCapability(VERSION_TRAILERS) && !newFormat.hasCapability(VERSION_TRAILERS);
if (movingAwayFromVersionTrailers) {
StoreFile.removeTrailers(versionToUpgradeFrom, fileSystem, storeDir, pageCache.pageSize());
}
File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
long logVersion = MetaDataStore.getRecord(pageCache, neoStore, Position.LOG_VERSION);
long lastCommittedTx = MetaDataStore.getRecord(pageCache, neoStore, Position.LAST_TRANSACTION_ID);
// update or add upgrade id and time and other necessary neostore records
updateOrAddNeoStoreFieldsAsPartOfMigration(migrationDir, storeDir, versionToUpgradeTo);
// delete old logs
legacyLogs.deleteUnusedLogFiles(storeDir);
if (movingAwayFromVersionTrailers) {
// write a check point in the log in order to make recovery work in the newer version
new StoreMigratorCheckPointer(storeDir, fileSystem).checkPoint(logVersion, lastCommittedTx);
}
}
use of java.util.function.Predicate in project neo4j by neo4j.
the class DelayedBufferTest method shouldHandleTheWholeWorkloadShebang.
@Test
public void shouldHandleTheWholeWorkloadShebang() throws Throwable {
// GIVEN
final int size = 1_000;
final long bufferTime = 3;
VerifyingConsumer consumer = new VerifyingConsumer(size);
final Clock clock = Clocks.systemClock();
Supplier<Long> chunkThreshold = clock::millis;
Predicate<Long> safeThreshold = time -> clock.millis() - bufferTime >= time;
final DelayedBuffer<Long> buffer = new DelayedBuffer<>(chunkThreshold, safeThreshold, 10, consumer);
MaintenanceThread maintenance = new MaintenanceThread(buffer, 5);
Race adders = new Race();
final int numberOfAdders = 20;
final byte[] offeredIds = new byte[size];
for (int i = 0; i < numberOfAdders; i++) {
final int finalI = i;
adders.addContestant(new Runnable() {
@Override
public void run() {
for (int j = 0; j < size; j++) {
if (j % numberOfAdders == finalI) {
buffer.offer(j);
offeredIds[j] = 1;
parkNanos(MILLISECONDS.toNanos(current().nextInt(2)));
}
}
}
});
}
// WHEN (multi-threadded) offering of ids
adders.go();
// ... ensuring the test is sane itself (did we really offer all these IDs?)
for (int i = 0; i < size; i++) {
assertEquals("ID " + i, (byte) 1, offeredIds[i]);
}
maintenance.halt();
buffer.close();
// THEN
consumer.assertHaveOnlySeenRange(0, size - 1);
}
Aggregations