Skip to content

Commit

Permalink
test: Simple ChartData tests for JS API
Browse files Browse the repository at this point in the history
Follow-up #6546
  • Loading branch information
niloc132 committed Jan 10, 2025
1 parent cfdeac2 commit 9239b40
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.deephaven.web.client.api.storage.JsStorageServiceTestGwt;
import io.deephaven.web.client.api.subscription.ConcurrentTableTestGwt;
import io.deephaven.web.client.api.subscription.ViewportTestGwt;
import io.deephaven.web.client.api.widget.plot.ChartDataTestGwt;
import io.deephaven.web.client.fu.LazyPromiseTestGwt;
import junit.framework.Test;
import junit.framework.TestSuite;
Expand All @@ -32,6 +33,7 @@ public static Test suite() {
suite.addTestSuite(InputTableTestGwt.class);
suite.addTestSuite(ColumnStatisticsTestGwt.class);
suite.addTestSuite(GrpcTransportTestGwt.class);
suite.addTestSuite(ChartDataTestGwt.class);

// This should be a unit test, but it requires a browser environment to run on GWT 2.9
// GWT 2.9 doesn't have proper bindings for Promises in HtmlUnit, so we need to use the IntegrationTest suite
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<module>
<!-- This test runs in its own module to avoid risking poisoning other tests with its broken custom transports -->
<inherits name="io.deephaven.web.DeephavenIntegrationTest" />
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
public class GrpcTransportTestGwt extends AbstractAsyncGwtTestCase {
@Override
public String getModuleName() {
return "io.deephaven.web.DeephavenIntegrationTest";
// This test runs in its own module to avoid risking poisoning other tests with its broken custom transports
return "io.deephaven.web.CustomTransportTest";
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package io.deephaven.web.client.api.widget.plot;

import elemental2.promise.Promise;
import io.deephaven.web.client.api.AbstractAsyncGwtTestCase;
import io.deephaven.web.client.api.subscription.AbstractTableSubscription;
import io.deephaven.web.client.api.subscription.TableSubscription;

public class ChartDataTestGwt extends AbstractAsyncGwtTestCase {
private final AbstractAsyncGwtTestCase.TableSourceBuilder tables = new AbstractAsyncGwtTestCase.TableSourceBuilder()
.script("from deephaven import time_table")
.script("appending_table", "time_table('PT0.1s').update([\"A = i % 2\", \"B = `` + A\"])")
.script("updating_table", "appending_table.last_by('A')");

@Override
public String getModuleName() {
return "io.deephaven.web.DeephavenIntegrationTest";
}

public void testAppendingChartData() {
connect(tables)
.then(table("appending_table"))
.then(table -> {
ChartData chartData = new ChartData(table);
TableSubscription sub = table.subscribe(table.getColumns());

// Handle at least one event with data
int[] count = {0};

return new Promise<AbstractTableSubscription.SubscriptionEventData>((resolve, reject) -> {
delayTestFinish(12301);
sub.addEventListener(TableSubscription.EVENT_UPDATED, event -> {
AbstractTableSubscription.SubscriptionEventData data = (AbstractTableSubscription.SubscriptionEventData) event.getDetail();
chartData.update(data);

if (count[0] > 0) {
// Don't test on the first update, could still be empty
assertTrue(chartData.getColumn("A", arr -> arr, data).length > 0);

resolve.onInvoke(data);
}
count[0]++;
});
}).then(data -> {
sub.close();
table.close();
return Promise.resolve(data);
});
})
.then(this::finish).catch_(this::report);
}

public void testModifiedChartData() {
connect(tables)
.then(table("updating_table"))
.then(table -> {
ChartData chartData = new ChartData(table);
TableSubscription sub = table.subscribe(table.getColumns());

int[] count = {0};
return new Promise<AbstractTableSubscription.SubscriptionEventData>((resolve, reject) -> {
delayTestFinish(12302);
sub.addEventListener(TableSubscription.EVENT_UPDATED, event -> {

AbstractTableSubscription.SubscriptionEventData data = (AbstractTableSubscription.SubscriptionEventData) event.getDetail();

chartData.update(data);
if (count[0] > 0) {
// Don't test on the first update, could still be empty
assertTrue(chartData.getColumn("A", arr -> arr, data).length > 0);
}

if (count[0] > 2) {
// We've seen at least three updates, and must have modified rows at least once
resolve.onInvoke((AbstractTableSubscription.SubscriptionEventData) event.getDetail());
}
count[0]++;
});
})
.then(data -> {
sub.close();
table.close();
return Promise.resolve(data);
});
})
.then(this::finish).catch_(this::report);
}
}

0 comments on commit 9239b40

Please sign in to comment.