Karibu Testing - DataProvider limit is always 1

I am using Karibu for testing my Vaadin Components, I hope this question is appropriate here. Whenever I need a DataProvider I create one for my tests. However, this only ever works if I only return one value, anything more than that and it will fail with the following exception:

java.lang.IllegalStateException: The number of items returned by the data provider exceeds the limit specified by the query (1).

This works:

return DataProvider.fromFilteringCallbacks(query -> {
	    var data = new SomeObj();
	    return Stream.of(data);
	}, query -> 1);

But this would fail:

return DataProvider.fromFilteringCallbacks(query -> {
	    var data1 = new SomeObj();
        var data2 = new SomeObj();
	    return Stream.of(data1, data2);
	}, query -> 2);

Did anyone get this to work?

Hard to say. Maybe the full stacktrace can provide some useful information.

Sure, this is the full stacktrace:

java.lang.IllegalStateException: The number of items returned by the data provider exceeds the limit specified by the query (1).
	at com.vaadin.flow.data.provider.DataCommunicator$SizeVerifier.accept(DataCommunicator.java:261)
	at java.base/java.util.stream.ReferencePipeline$15$1.accept(ReferencePipeline.java:540)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575)
	at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622)
	at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627)
	at com.github.mvysny.kaributesting.v10.GridKt.fetch(Grid.kt:209)
	at com.github.mvysny.kaributesting.v10.GridKt._fetch(Grid.kt:165)
	at com.github.mvysny.kaributesting.v10.GridKt._getOrNull(Grid.kt:121)
	at com.github.mvysny.kaributesting.v10.GridKt._get(Grid.kt:97)
	at com.github.mvysny.kaributesting.v10.GridKt._getFormatted(Grid.kt:376)
	at at.cmp.app.web.team.EditTeamComponentTest.testCreateEditTeamComponent(EditTeamComponentTest.java:75)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Personally I can’t find anything telling in it.

What exactly does the test? I’m trying to understand if it could be a bug in Karibu’s GridKt or something else.

The test just creates the component and asserts that the expected components/properties are there.
In this case it happens when testing a Grid which is part of the component, these are the two lines where I test the Grid:

var grid = (Grid<SomeData>) LocatorJ._get(editTeamComponent, Grid.class);
Assertions.assertEquals("SomeString", GridKt._getFormatted(grid, 0, "columnKey"));

Specifically, the second line is line 75 in my test class which is referenced in the stacktrace.

From the karibu docs it’s clear why:

[…] they [the filters] are invoked every time you call one of Karibu-Testing’s GridKt methods such as expectRows() or expectRow() or _clickRenderer(), or one of the “lower-level” functions _get(0) or _size() or _getFormattedRow().

The issue could be that your data provider callbacks are ignoring the limit requested by Query.getLimit()

Yes, that was exactly it and makes perfect sense now. Thank you!