|
| 1 | +// |
| 2 | +// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending |
| 3 | +// |
| 4 | +package io.deephaven.web.client.api.widget.plot; |
| 5 | + |
| 6 | +import elemental2.promise.Promise; |
| 7 | +import io.deephaven.web.client.api.AbstractAsyncGwtTestCase; |
| 8 | +import io.deephaven.web.client.api.subscription.AbstractTableSubscription; |
| 9 | +import io.deephaven.web.client.api.subscription.TableSubscription; |
| 10 | + |
| 11 | +public class ChartDataTestGwt extends AbstractAsyncGwtTestCase { |
| 12 | + private final AbstractAsyncGwtTestCase.TableSourceBuilder tables = new AbstractAsyncGwtTestCase.TableSourceBuilder() |
| 13 | + .script("from deephaven import time_table") |
| 14 | + .script("appending_table", "time_table('PT0.1s').update([\"A = i % 2\", \"B = `` + A\"])") |
| 15 | + .script("updating_table", "appending_table.last_by('A')"); |
| 16 | + |
| 17 | + @Override |
| 18 | + public String getModuleName() { |
| 19 | + return "io.deephaven.web.DeephavenIntegrationTest"; |
| 20 | + } |
| 21 | + |
| 22 | + public void testAppendingChartData() { |
| 23 | + connect(tables) |
| 24 | + .then(table("appending_table")) |
| 25 | + .then(table -> { |
| 26 | + ChartData chartData = new ChartData(table); |
| 27 | + TableSubscription sub = table.subscribe(table.getColumns()); |
| 28 | + |
| 29 | + // Handle at least one event with data |
| 30 | + int[] count = {0}; |
| 31 | + |
| 32 | + return new Promise<AbstractTableSubscription.SubscriptionEventData>((resolve, reject) -> { |
| 33 | + delayTestFinish(12301); |
| 34 | + sub.addEventListener(TableSubscription.EVENT_UPDATED, event -> { |
| 35 | + AbstractTableSubscription.SubscriptionEventData data = |
| 36 | + (AbstractTableSubscription.SubscriptionEventData) event.getDetail(); |
| 37 | + chartData.update(data); |
| 38 | + |
| 39 | + if (count[0] > 0) { |
| 40 | + // Don't test on the first update, could still be empty |
| 41 | + assertTrue(chartData.getColumn("A", arr -> arr, data).length > 0); |
| 42 | + |
| 43 | + resolve.onInvoke(data); |
| 44 | + } |
| 45 | + count[0]++; |
| 46 | + }); |
| 47 | + }).then(data -> { |
| 48 | + sub.close(); |
| 49 | + table.close(); |
| 50 | + return Promise.resolve(data); |
| 51 | + }); |
| 52 | + }) |
| 53 | + .then(this::finish).catch_(this::report); |
| 54 | + } |
| 55 | + |
| 56 | + public void testModifiedChartData() { |
| 57 | + connect(tables) |
| 58 | + .then(table("updating_table")) |
| 59 | + .then(table -> { |
| 60 | + ChartData chartData = new ChartData(table); |
| 61 | + TableSubscription sub = table.subscribe(table.getColumns()); |
| 62 | + |
| 63 | + int[] count = {0}; |
| 64 | + return new Promise<AbstractTableSubscription.SubscriptionEventData>((resolve, reject) -> { |
| 65 | + delayTestFinish(12302); |
| 66 | + sub.addEventListener(TableSubscription.EVENT_UPDATED, event -> { |
| 67 | + |
| 68 | + AbstractTableSubscription.SubscriptionEventData data = |
| 69 | + (AbstractTableSubscription.SubscriptionEventData) event.getDetail(); |
| 70 | + |
| 71 | + chartData.update(data); |
| 72 | + if (count[0] > 0) { |
| 73 | + // Don't test on the first update, could still be empty |
| 74 | + assertTrue(chartData.getColumn("A", arr -> arr, data).length > 0); |
| 75 | + } |
| 76 | + |
| 77 | + if (count[0] > 2) { |
| 78 | + // We've seen at least three updates, and must have modified rows at least once |
| 79 | + resolve.onInvoke((AbstractTableSubscription.SubscriptionEventData) event.getDetail()); |
| 80 | + } |
| 81 | + count[0]++; |
| 82 | + }); |
| 83 | + }) |
| 84 | + .then(data -> { |
| 85 | + sub.close(); |
| 86 | + table.close(); |
| 87 | + return Promise.resolve(data); |
| 88 | + }); |
| 89 | + }) |
| 90 | + .then(this::finish).catch_(this::report); |
| 91 | + } |
| 92 | +} |
0 commit comments