Skip to content

Commit

Permalink
Add test for infinite loop replication (#481)
Browse files Browse the repository at this point in the history
* Add test for infinite loop replication

Signed-off-by: Daniel Henneberger <git@danielhenneberger.com>

* Enable test

Signed-off-by: Daniel Henneberger <git@danielhenneberger.com>

* Slim down example

Signed-off-by: Daniel Henneberger <git@danielhenneberger.com>

---------

Signed-off-by: Daniel Henneberger <git@danielhenneberger.com>
  • Loading branch information
henneberger authored Jan 18, 2024
1 parent 07c8b74 commit ec5ea02
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class TestCmd {

private static final Path OUTPUT_DIR = Paths.get("src", "test", "resources", "output");
private static final Path SUBSCRIPTION_PATH = Paths.get("src/test/resources/subscriptions");
private static final Path CC_PATH = Paths.get("src/test/resources/creditcard");

protected Path buildDir = null;
SnapshotTest.Snapshot snapshot;
Expand Down Expand Up @@ -174,6 +175,14 @@ public void discoverRetail() {
createSnapshot();
}

// SQRL #479 - Infinite loop replication
@Test
public void testCreditCardInfiniteLoop() {
Path basePath = CC_PATH;
execute(basePath,
"compile", basePath.resolve("creditcard.sqrl").toString(), basePath.resolve("creditcard.graphqls").toString());
}

public static int execute(Path rootDir, String... args) {
return execute(rootDir, AssertStatusHook.INSTANCE, args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type Query {
CustomerSpending(customerid: Int!, fromTime: String!, toTime: String!, limit: Int = 10, offset: Int = 0): [CustomerSpending!]
}

type CustomerSpending {
category: String!
spending: Float!
}
19 changes: 19 additions & 0 deletions sqrl-tools/sqrl-cli/src/test/resources/creditcard/creditcard.sqrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
IMPORT creditcard.Merchant;
IMPORT creditcard.Assignment AS CardAssignment;
IMPORT creditcard.Transaction;
IMPORT time.*;

Merchant := DISTINCT Merchant ON merchantId ORDER BY updatedTime DESC;
CardAssignment := DISTINCT CardAssignment ON cardNo ORDER BY timestamp DESC;

CustomerSpendingByDay := SELECT customerid, endOfDay(time) as timeDay, category, SUM(amount) as spending
FROM Transaction t
JOIN CardAssignment c ON t.cardNo = c.cardNo
JOIN Merchant m ON t.merchantId = m.merchantid
GROUP BY customerid, timeDay, category;

CustomerSpending(@customerid: BIGINT, @fromTime: TIMESTAMP, @toTime: TIMESTAMP) :=
SELECT category, SUM(spending) as spending
FROM CustomerSpendingByDay WHERE customerid = @customerid AND @fromTime <= timeDay AND @toTime > timeDay
GROUP BY category ORDER BY category ASC;

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: "assignment"
schema_version: "1"
partial_schema: false
columns:
- name: "customerId"
type: "BIGINT"
tests:
- "not_null"
- name: "cardNo"
type: "STRING"
tests:
- "not_null"
- name: "timestamp"
type: "TIMESTAMP"
tests:
- "not_null"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"format" : {
"name" : "json"
},
"schema" : "flexible",
"identifier" : "assignment",
"type" : "source",
"connector" : {
"name" : "file",
"directoryURI" : "../../sqrl-examples/creditcard/data"
},
"canonicalizer" : "system"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: "merchant"
schema_version: "1"
partial_schema: false
columns:
- name: "merchantId"
type: "BIGINT"
tests:
- "not_null"
- name: "name"
type: "STRING"
tests:
- "not_null"
- name: "category"
type: "STRING"
tests:
- "not_null"
- name: "updatedTime"
type: "TIMESTAMP"
tests:
- "not_null"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"format" : {
"name" : "json"
},
"schema" : "flexible",
"identifier" : "merchant",
"type" : "source",
"connector" : {
"name" : "file",
"directoryURI" : "../../sqrl-examples/creditcard/data"
},
"canonicalizer" : "system"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: "transaction"
schema_version: "1"
partial_schema: false
columns:
- name: "transactionId"
type: "BIGINT"
tests:
- "not_null"
- name: "cardNo"
type: "STRING"
tests:
- "not_null"
- name: "time"
type: "TIMESTAMP"
tests:
- "not_null"
- name: "amount"
type: "DOUBLE"
tests:
- "not_null"
- name: "merchantId"
type: "BIGINT"
tests:
- "not_null"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"format" : {
"name" : "json"
},
"schema" : "flexible",
"identifier" : "transaction",
"type" : "source",
"connector" : {
"name" : "file",
"directoryURI" : "../../sqrl-examples/creditcard/data"
},
"canonicalizer" : "system"
}

0 comments on commit ec5ea02

Please sign in to comment.