Search in sources :

Example 6 with BooleanSupplier

use of java.util.function.BooleanSupplier in project elasticsearch by elastic.

the class IndicesLifecycleListenerIT method assertShardStatesMatch.

private static void assertShardStatesMatch(final IndexShardStateChangeListener stateChangeListener, final int numShards, final IndexShardState... shardStates) throws InterruptedException {
    BooleanSupplier waitPredicate = () -> {
        if (stateChangeListener.shardStates.size() != numShards) {
            return false;
        }
        for (List<IndexShardState> indexShardStates : stateChangeListener.shardStates.values()) {
            if (indexShardStates == null || indexShardStates.size() != shardStates.length) {
                return false;
            }
            for (int i = 0; i < shardStates.length; i++) {
                if (indexShardStates.get(i) != shardStates[i]) {
                    return false;
                }
            }
        }
        return true;
    };
    if (!awaitBusy(waitPredicate, 1, TimeUnit.MINUTES)) {
        fail("failed to observe expect shard states\n" + "expected: [" + numShards + "] shards with states: " + Strings.arrayToCommaDelimitedString(shardStates) + "\n" + "observed:\n" + stateChangeListener);
    }
    stateChangeListener.shardStates.clear();
}
Also used : List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BooleanSupplier(java.util.function.BooleanSupplier)

Example 7 with BooleanSupplier

use of java.util.function.BooleanSupplier in project neo4j by neo4j.

the class CatchupStoreCopyInteractionStressTesting method shouldBehaveCorrectlyUnderStress.

@Test
public void shouldBehaveCorrectlyUnderStress() throws Exception {
    int numberOfCores = parseInt(fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_CORES", DEFAULT_NUMBER_OF_CORES));
    int numberOfEdges = parseInt(fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_EDGES", DEFAULT_NUMBER_OF_EDGES));
    long durationInMinutes = parseLong(fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
    String workingDirectory = fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_WORKING_DIRECTORY", DEFAULT_WORKING_DIR);
    boolean enableIndexes = parseBoolean(fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_ENABLE_INDEXES", DEFAULT_ENABLE_INDEXES));
    String txPrune = fromEnv("CATCHUP_STORE_COPY_INTERACTION_STRESS_TX_PRUNE", DEFAULT_TX_PRUNE);
    File clusterDirectory = ensureExistsAndEmpty(new File(workingDirectory, "cluster"));
    Map<String, String> coreParams = enableRaftMessageLogging(configureRaftLogRotationAndPruning(configureTxLogRotationAndPruning(new HashMap<>(), txPrune)));
    Map<String, String> edgeParams = configureTxLogRotationAndPruning(new HashMap<>(), txPrune);
    HazelcastDiscoveryServiceFactory discoveryServiceFactory = new HazelcastDiscoveryServiceFactory();
    Cluster cluster = new Cluster(clusterDirectory, numberOfCores, numberOfEdges, discoveryServiceFactory, coreParams, emptyMap(), edgeParams, emptyMap(), Standard.LATEST_NAME);
    AtomicBoolean stopTheWorld = new AtomicBoolean();
    BooleanSupplier notExpired = untilTimeExpired(durationInMinutes, MINUTES);
    BooleanSupplier keepGoing = () -> !stopTheWorld.get() && notExpired.getAsBoolean();
    Runnable onFailure = () -> stopTheWorld.set(true);
    ExecutorService service = Executors.newCachedThreadPool();
    try {
        cluster.start();
        if (enableIndexes) {
            Workload.setupIndexes(cluster);
        }
        Future<Throwable> workload = service.submit(new Workload(keepGoing, onFailure, cluster));
        Future<Throwable> startStopWorker = service.submit(new StartStopLoad(fs, pageCache, keepGoing, onFailure, cluster, numberOfCores, numberOfEdges));
        Future<Throwable> catchUpWorker = service.submit(new CatchUpLoad(keepGoing, onFailure, cluster));
        long timeout = durationInMinutes + 5;
        assertNull(Exceptions.stringify(workload.get()), workload.get(timeout, MINUTES));
        assertNull(Exceptions.stringify(startStopWorker.get()), startStopWorker.get(timeout, MINUTES));
        assertNull(Exceptions.stringify(catchUpWorker.get()), catchUpWorker.get(timeout, MINUTES));
    } finally {
        cluster.shutdown();
        service.shutdown();
    }
    // let's cleanup disk space when everything went well
    FileUtils.deleteRecursively(clusterDirectory);
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) BooleanSupplier(java.util.function.BooleanSupplier) Test(org.junit.Test)

Example 8 with BooleanSupplier

use of java.util.function.BooleanSupplier in project RecurrentComplex by Ivorforce.

the class TableCellMultiBuilder method build.

@Nonnull
public TableCellDefault build() {
    List<TableCellButton> cells = new ArrayList<>();
    for (int i = 0; i < this.cells.size(); i++) {
        TableCellButton cell = this.cells.get(i).get();
        cell.setId("action." + i);
        cell.actionID = "action." + i;
        BooleanSupplier enabled = enabledSuppliers.get(i);
        if (enabled != null)
            cell.setEnabled(enabled.getAsBoolean());
        cells.add(cell);
    }
    return new TableCellMulti(cells);
}
Also used : ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) Nonnull(javax.annotation.Nonnull)

Aggregations

BooleanSupplier (java.util.function.BooleanSupplier)8 File (java.io.File)3 ExecutorService (java.util.concurrent.ExecutorService)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Cluster (org.neo4j.causalclustering.discovery.Cluster)2 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)2 Proposition (il.org.spartan.utils.Proposition)1 NestedLoopBatchIterator (io.crate.data.join.NestedLoopBatchIterator)1 IOException (java.io.IOException)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 Integer.parseInt (java.lang.Integer.parseInt)1 Long.parseLong (java.lang.Long.parseLong)1 System.getProperty (java.lang.System.getProperty)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Stack (java.util.Stack)1