Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Simple ChartData tests for JS API #6549

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,92 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
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);
}
}