use of org.junit.Assert.assertTrue in project flow by vaadin.
the class BootstrapHandlerTest method theme_contents_are_appended_to_head_for_alias_route.
// 3333
@Test
public void theme_contents_are_appended_to_head_for_alias_route() throws InvalidRouteConfigurationException {
HttpServletRequest request = createRequest();
Mockito.doAnswer(invocation -> "/alias").when(request).getPathInfo();
VaadinServletRequest aliasRequest = new VaadinServletRequest(request, service);
initUI(testUI, aliasRequest, Collections.singleton(MyAliasThemeTest.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(aliasRequest, null, session, testUI));
Elements allElements = page.head().getAllElements();
Assert.assertTrue("Custom style should have been added to head.", allElements.stream().map(Object::toString).anyMatch(element -> element.equals("<link rel=\"import\" href=\"./frontend/bower_components/vaadin-lumo-styles/color.html\">")));
allElements = page.body().getAllElements();
// Note element 0 is the full head element.
assertStringEquals("Custom style should have been added to head.", "<custom-style><style include=\"lumo-typography\"></style></custom-style>", allElements.get(2).toString());
Assert.assertTrue("Style should have been wrapped in custom style", page.body().toString().contains("<custom-style><style include=\"lumo-typography\"></style></custom-style>"));
}
use of org.junit.Assert.assertTrue in project flow by vaadin.
the class BootstrapHandlerTest method theme_contents_are_appended_to_head.
// 3197
@Test
public void theme_contents_are_appended_to_head() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(MyThemeTest.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.head().getAllElements();
Assert.assertTrue("Custom style should have been added to head.", allElements.stream().map(Object::toString).anyMatch(element -> element.equals("<link rel=\"import\" href=\"./frontend/bower_components/vaadin-lumo-styles/color.html\">")));
allElements = page.body().getAllElements();
// Note element 0 is the full head element.
assertStringEquals("Custom style should have been added to head.", "<custom-style><style include=\"lumo-typography\"></style></custom-style>", allElements.get(2).toString());
Assert.assertTrue("Style should have been wrapped in custom style", page.body().toString().contains("<custom-style><style include=\"lumo-typography\"></style></custom-style>"));
}
use of org.junit.Assert.assertTrue 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);
}
}
use of org.junit.Assert.assertTrue in project pravega by pravega.
the class IteratorTest method testContinuationTokenIterator.
@Test(timeout = 10000L)
public void testContinuationTokenIterator() {
List<Integer> toReturn = IntStream.range(0, 25).boxed().collect(Collectors.toList());
AtomicInteger timesCalled = new AtomicInteger(0);
ContinuationTokenAsyncIterator<String, Integer> iterator = getIterator(toReturn, timesCalled);
// region sequential calls
Integer next = iterator.getNext().join();
int found = 0;
while (next != null) {
assertEquals(next.intValue(), found++);
next = iterator.getNext().join();
}
assertEquals(4, timesCalled.get());
assertEquals(25, found);
// endregion
// region concurrent calls
timesCalled = new AtomicInteger(0);
iterator = getIterator(toReturn, timesCalled);
ConcurrentHashMap<Integer, Integer> foundMap = new ConcurrentHashMap<>();
List<CompletableFuture<Void>> futures = new LinkedList<>();
for (int i = 0; i < 26; i++) {
futures.add(iterator.getNext().thenAccept(x -> {
if (x != null) {
foundMap.compute(x, (r, s) -> {
if (s != null) {
return s + 1;
} else {
return 1;
}
});
}
}));
}
Futures.allOf(futures).join();
Assert.assertEquals(4, timesCalled.get());
assertEquals(25, foundMap.size());
Assert.assertTrue(foundMap.entrySet().stream().allMatch(x -> x.getValue() == 1));
// endregion
// region concurrent calls
CompletableFuture<Void> latch = new CompletableFuture<>();
List<Integer> list = Lists.newArrayList(1, 2, 3);
AtomicInteger functionCalledCount = new AtomicInteger(0);
iterator = spy(new ContinuationTokenAsyncIterator<>(s -> {
functionCalledCount.incrementAndGet();
int startIndex = Strings.isNullOrEmpty(s) ? 0 : Integer.parseInt(s);
int endIndex = startIndex + 1;
if (!Strings.isNullOrEmpty(s)) {
// block the call
return latch.thenApply(v -> {
List<Integer> tmp = (startIndex >= list.size()) ? Lists.newArrayList() : list.subList(startIndex, endIndex);
return new AbstractMap.SimpleEntry<>("" + endIndex, tmp);
});
}
CompletableFuture<Map.Entry<String, Collection<Integer>>> completedFuture = CompletableFuture.completedFuture(new AbstractMap.SimpleEntry<String, Collection<Integer>>("" + endIndex, list.subList(startIndex, endIndex)));
return completedFuture;
}, ""));
Integer next0 = iterator.getNext().join();
assertEquals(next0.intValue(), 1);
assertEquals(1, functionCalledCount.get());
assertEquals(iterator.getToken(), "1");
CompletableFuture<Integer> next1 = iterator.getNext();
// wait until first call is made.
assertEquals("1", iterator.getToken());
CompletableFuture<Integer> next2 = iterator.getNext();
// this should keep calling getNext in a loop until it gets the value.
// verify that iterator.getNext is called multiple times.
verify(iterator, atLeast(3)).getNext();
assertEquals(2, functionCalledCount.get());
// signal to complete getNext with token "1"
latch.complete(null);
// since next1 and next2 are called concurrently, there is no guarantee on their order.
assertEquals(next1.join() + next2.join(), 5);
assertEquals(3, functionCalledCount.get());
assertEquals(iterator.getToken(), "3");
assertTrue(iterator.isInternalQueueEmpty());
assertNull(iterator.getNext().join());
// endregion
}
use of org.junit.Assert.assertTrue in project pravega by pravega.
the class StreamSegmentContainerTests method testExtensions.
/**
* Tests the ability to register extensions.
*/
@Test
public void testExtensions() throws Exception {
String segmentName = getSegmentName(123);
ByteArraySegment data = getAppendData(segmentName, 0);
// Configure extension.
val operationProcessed = new CompletableFuture<SegmentOperation>();
AtomicInteger count = new AtomicInteger();
val writerProcessor = new TestWriterProcessor(op -> {
if (op.getStreamSegmentId() != EXPECTED_METADATA_SEGMENT_ID) {
// We need to exclude any appends that come from the MetadataStore as those do not concern us.
count.incrementAndGet();
if (!operationProcessed.isDone()) {
operationProcessed.complete(op);
}
}
});
val extension = new AtomicReference<TestSegmentContainerExtension>();
SegmentContainerFactory.CreateExtensions additionalExtensions = (container, executor) -> {
Assert.assertTrue("Already created", extension.compareAndSet(null, new TestSegmentContainerExtension(Collections.singleton(writerProcessor))));
return Collections.singletonMap(TestSegmentContainerExtension.class, extension.get());
};
@Cleanup val context = new TestContext(DEFAULT_CONFIG, additionalExtensions);
context.container.startAsync().awaitRunning();
// Verify getExtension().
val p = context.container.getExtension(TestSegmentContainerExtension.class);
Assert.assertEquals("Unexpected result from getExtension().", extension.get(), p);
// Verify Writer Segment Processors are properly wired in.
context.container.createStreamSegment(segmentName, getSegmentType(segmentName), null, TIMEOUT).join();
context.container.append(segmentName, data, null, TIMEOUT).join();
val rawOp = operationProcessed.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
Assert.assertTrue("Unexpected operation type.", rawOp instanceof CachedStreamSegmentAppendOperation);
// Our operation has been transformed into a CachedStreamSegmentAppendOperation, which means it just points to
// a location in the cache. We do not have access to that cache, so we can only verify its metadata.
val appendOp = (CachedStreamSegmentAppendOperation) rawOp;
Assert.assertEquals("Unexpected offset.", 0, appendOp.getStreamSegmentOffset());
Assert.assertEquals("Unexpected data length.", data.getLength(), appendOp.getLength());
Assert.assertNull("Unexpected attribute updates.", appendOp.getAttributeUpdates());
// Verify extension is closed when the SegmentContainer is closed.
context.container.close();
Assert.assertTrue("Extension not closed.", extension.get().closed.get());
}
Aggregations