use of org.junit.Assert.fail in project bookkeeper by apache.
the class BookieWriteLedgerTest method testLedgerCreateAdvWithLedgerIdInLoop.
/**
* In a loop create/write/delete the ledger with same ledgerId through
* the functionality of Advanced Ledger which accepts ledgerId as input.
*
* @throws Exception
*/
@Test
public void testLedgerCreateAdvWithLedgerIdInLoop() throws Exception {
int ledgerCount = 40;
long maxId = 9999999999L;
if (baseConf.getLedgerManagerFactoryClass().equals(LongHierarchicalLedgerManagerFactory.class)) {
// since LongHierarchicalLedgerManager supports ledgerIds of decimal length upto 19 digits but other
// LedgerManagers only upto 10 decimals
maxId = Long.MAX_VALUE;
}
// generate a stream of ledger ids
rng.longs(ledgerCount, 0, maxId).mapToObj(ledgerId -> {
// create a ledger for each ledger id
LOG.info("Creating adv ledger with id {}", ledgerId);
return bkc.newCreateLedgerOp().withEnsembleSize(1).withWriteQuorumSize(1).withAckQuorumSize(1).withDigestType(org.apache.bookkeeper.client.api.DigestType.CRC32).withPassword(ledgerPassword).makeAdv().withLedgerId(ledgerId).execute().thenApply(writer -> {
// Add entries to ledger when created
LOG.info("Writing stream of {} entries to {}", numEntriesToWrite, ledgerId);
List<ByteBuf> entries = rng.ints(numEntriesToWrite, 0, maxInt).mapToObj(i -> {
ByteBuf entry = Unpooled.buffer(4);
entry.retain();
entry.writeInt(i);
return entry;
}).collect(Collectors.toList());
CompletableFuture<?> lastRequest = null;
int i = 0;
for (ByteBuf entry : entries) {
long entryId = i++;
LOG.info("Writing {}:{} as {}", ledgerId, entryId, entry.slice().readInt());
lastRequest = writer.writeAsync(entryId, entry);
}
lastRequest.join();
return Pair.of(writer, entries);
});
}).parallel().map(// wait for all creations and adds in parallel
CompletableFuture::join).forEach(e -> {
// check that each set of adds succeeded
try {
WriteAdvHandle handle = e.getLeft();
List<ByteBuf> entries = e.getRight();
// Read and verify
LOG.info("Read entries for ledger: {}", handle.getId());
readEntries(handle, entries);
entries.forEach(ByteBuf::release);
handle.close();
bkc.deleteLedger(handle.getId());
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
Assert.fail("Test interrupted");
} catch (Exception ex) {
LOG.info("Readback failed with exception", ex);
Assert.fail("Readback failed " + ex.getMessage());
}
});
}
use of org.junit.Assert.fail in project open-kilda by telstra.
the class StatsTopologyTest method flowAttendantRulesStatsTest.
@Test
public void flowAttendantRulesStatsTest() {
Flow flow = createFlow();
FlowSegmentCookie server42IngressCookie = MAIN_FORWARD_COOKIE.toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build();
FlowEndpoint ingress = new FlowEndpoint(SWITCH_ID_1, PORT_1);
FlowStatsEntry measure0 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 0, 0, ingress.getPortNumber(), ingress.getPortNumber() + 1);
FlowStatsEntry measure1 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 1, 200, ingress.getPortNumber(), ingress.getPortNumber() + 1);
FlowStatsEntry measure2 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 2, 300, ingress.getPortNumber(), ingress.getPortNumber() + 1);
sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure0)));
sendUpdateFlowPathInfo(flow.getForwardPath());
sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure1)));
sendRemoveFlowPathInfo(flow.getForwardPath());
sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure2)));
List<Datapoint> datapoints = pollDatapoints(9);
List<Datapoint> rawPacketsMetric = datapoints.stream().filter(entry -> (METRIC_PREFIX + "flow.raw.packets").equals(entry.getMetric())).collect(Collectors.toList());
Assert.assertEquals(3, rawPacketsMetric.size());
for (Datapoint entry : rawPacketsMetric) {
Map<String, String> tags = entry.getTags();
Assert.assertEquals(CookieType.SERVER_42_FLOW_RTT_INGRESS.name().toLowerCase(), tags.get("type"));
if (Objects.equals(0, entry.getValue())) {
Assert.assertEquals("unknown", tags.get("flowid"));
} else if (Objects.equals(1, entry.getValue())) {
Assert.assertEquals(flowId, tags.get("flowid"));
} else if (Objects.equals(2, entry.getValue())) {
Assert.assertEquals("unknown", tags.get("flowid"));
} else {
Assert.fail(format("Unexpected metric value: %s", entry));
}
}
}
use of org.junit.Assert.fail in project graal by oracle.
the class SLExceptionTest method assertException.
private void assertException(boolean failImmediately, String source, String... expectedFrames) {
boolean initialExecute = true;
try {
Value value = ctx.eval("sl", source);
initialExecute = false;
if (failImmediately) {
Assert.fail("Should not reach here.");
}
ProxyExecutable proxy = (args) -> args[0].execute();
value.execute(proxy);
Assert.fail("Should not reach here.");
} catch (PolyglotException e) {
Assert.assertEquals(failImmediately, initialExecute);
assertFrames(failImmediately, e, expectedFrames);
}
}
use of org.junit.Assert.fail in project graal by oracle.
the class SLExceptionTest method assertHostException.
private void assertHostException(String source, String... expectedFrames) {
boolean initialExecute = true;
RuntimeException[] exception = new RuntimeException[1];
try {
Value value = ctx.eval("sl", source);
initialExecute = false;
ProxyExecutable proxy = (args) -> {
throw exception[0] = new RuntimeException();
};
value.execute(proxy);
Assert.fail("Should not reach here.");
} catch (PolyglotException e) {
Assert.assertFalse(initialExecute);
Assert.assertTrue(e.asHostException() == exception[0]);
assertFrames(false, e, expectedFrames);
}
}
Aggregations