use of org.junit.Assert in project elasticsearch by elastic.
the class InternalTestCluster method fullRestart.
/**
* Restarts all nodes in the cluster. It first stops all nodes and then restarts all the nodes again.
*/
public synchronized void fullRestart(RestartCallback callback) throws Exception {
int numNodesRestarted = 0;
Map<Set<Role>, List<NodeAndClient>> nodesByRoles = new HashMap<>();
Set[] rolesOrderedByOriginalStartupOrder = new Set[nextNodeId.get()];
for (NodeAndClient nodeAndClient : nodes.values()) {
callback.doAfterNodes(numNodesRestarted++, nodeAndClient.nodeClient());
logger.info("Stopping node [{}] ", nodeAndClient.name);
if (activeDisruptionScheme != null) {
activeDisruptionScheme.removeFromNode(nodeAndClient.name, this);
}
nodeAndClient.closeNode();
// delete data folders now, before we start other nodes that may claim it
nodeAndClient.clearDataIfNeeded(callback);
DiscoveryNode discoveryNode = getInstanceFromNode(ClusterService.class, nodeAndClient.node()).localNode();
rolesOrderedByOriginalStartupOrder[nodeAndClient.nodeAndClientId] = discoveryNode.getRoles();
nodesByRoles.computeIfAbsent(discoveryNode.getRoles(), k -> new ArrayList<>()).add(nodeAndClient);
}
assert nodesByRoles.values().stream().collect(Collectors.summingInt(List::size)) == nodes.size();
// will still belong to data nodes
for (List<NodeAndClient> sameRoleNodes : nodesByRoles.values()) {
Collections.shuffle(sameRoleNodes, random);
}
List<NodeAndClient> startUpOrder = new ArrayList<>();
for (Set roles : rolesOrderedByOriginalStartupOrder) {
if (roles == null) {
// if some nodes were stopped, we want have a role for that ordinal
continue;
}
final List<NodeAndClient> nodesByRole = nodesByRoles.get(roles);
startUpOrder.add(nodesByRole.remove(0));
}
assert nodesByRoles.values().stream().collect(Collectors.summingInt(List::size)) == 0;
// do two rounds to minimize pinging (mock zen pings pings with no delay and can create a lot of logs)
for (NodeAndClient nodeAndClient : startUpOrder) {
logger.info("resetting node [{}] ", nodeAndClient.name);
// we already cleared data folders, before starting nodes up
nodeAndClient.recreateNodeOnRestart(callback, false, autoManageMinMasterNodes ? getMinMasterNodes(getMasterNodesCount()) : -1);
}
startAndPublishNodesAndClients(startUpOrder);
if (callback.validateClusterForming()) {
validateClusterFormed();
}
}
use of org.junit.Assert in project java-design-patterns by iluwatar.
the class SimpleFileWriterTest method testWriterNotNull.
/**
* Verify if the given writer is not 'null'
*/
@Test
public void testWriterNotNull() throws Exception {
final File temporaryFile = this.testFolder.newFile();
new SimpleFileWriter(temporaryFile.getPath(), Assert::assertNotNull);
}
use of org.junit.Assert in project neo4j by neo4j.
the class NeoStoreFileListingTest method shouldListNeostoreDbLast.
@Test
public void shouldListNeostoreDbLast() throws Exception {
Boolean[] foundStoreType = new Boolean[StoreType.values().length];
boolean foundTxLogs = false;
final ResourceIterator<StoreFileMetadata> storeFiles = neoStoreDataSource.listStoreFiles(true);
while (storeFiles.hasNext()) {
final StoreFileMetadata storeFile = storeFiles.next();
if (storeFile.storeType().isPresent()) {
StoreType storeType = storeFile.storeType().get();
foundStoreType[storeType.ordinal()] = true;
if (storeType == StoreType.META_DATA) {
Arrays.stream(foundStoreType).forEach(Assert::assertTrue);
assertTrue("Transaction logs was not listed before neostore.db", foundTxLogs);
}
} else if (transactionLogFile(storeFile.file().getName())) {
foundTxLogs = true;
}
}
}
use of org.junit.Assert in project spring-framework by spring-projects.
the class AsyncRestTemplateIntegrationTests method deleteCallbackWithLambdas.
@Test
public void deleteCallbackWithLambdas() throws Exception {
ListenableFuture<?> deletedFuture = template.delete(new URI(baseUrl + "/delete"));
deletedFuture.addCallback(Assert::assertNull, ex -> fail(ex.getMessage()));
waitTillDone(deletedFuture);
}
use of org.junit.Assert in project cassandra by apache.
the class LongBTreeTest method randomKeys.
// select a random subset of the keys, with an optional random population of keys inbetween those that are present
// return a value with the search position
private static List<Integer> randomKeys(Iterable<Integer> canonical, boolean mixInNotPresentItems) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
boolean useFake = mixInNotPresentItems && rnd.nextBoolean();
final float fakeRatio = rnd.nextFloat();
List<Integer> results = new ArrayList<>();
Long fakeLb = (long) Integer.MIN_VALUE, fakeUb = null;
Integer max = null;
for (Integer v : canonical) {
if (!useFake || (fakeUb == null ? v - 1 : fakeUb) <= fakeLb + 1 || rnd.nextFloat() < fakeRatio) {
// if we cannot safely construct a fake value, or our randomizer says not to, we emit the next real value
results.add(v);
fakeLb = v.longValue();
fakeUb = null;
} else {
// exceeding the real value that would have proceeded (ignoring any other suppressed real values since)
if (fakeUb == null)
fakeUb = v.longValue() - 1;
long mid = (fakeLb + fakeUb) / 2;
assert mid < fakeUb;
results.add((int) mid);
fakeLb = mid;
}
max = v;
}
if (useFake && max != null && max < Integer.MAX_VALUE)
results.add(max + 1);
final float useChance = rnd.nextFloat();
return Lists.newArrayList(filter(results, (x) -> rnd.nextFloat() < useChance));
}
Aggregations