1
1
package apoc .load ;
2
2
3
- import apoc .util . s3 . MySQLContainerExtension ;
3
+ import apoc .periodic . Periodic ;
4
4
import apoc .util .TestUtil ;
5
5
import apoc .util .Util ;
6
+ import apoc .util .s3 .MySQLContainerExtension ;
6
7
import org .junit .AfterClass ;
7
8
import org .junit .BeforeClass ;
8
9
import org .junit .ClassRule ;
9
10
import org .junit .Test ;
10
11
import org .junit .experimental .runners .Enclosed ;
11
12
import org .junit .runner .RunWith ;
13
+ import org .neo4j .graphdb .Result ;
12
14
import org .neo4j .test .rule .DbmsRule ;
13
15
import org .neo4j .test .rule .ImpermanentDbmsRule ;
14
16
19
21
import java .util .Map ;
20
22
21
23
import static apoc .util .TestUtil .testCall ;
24
+ import static apoc .util .TestUtil .testCallEventually ;
22
25
import static org .junit .Assert .assertEquals ;
23
26
import static org .junit .Assert .assertTrue ;
24
27
@@ -36,7 +39,7 @@ public static class MySQLJdbcLatestVersionTest {
36
39
@ BeforeClass
37
40
public static void setUpContainer () {
38
41
mysql .start ();
39
- TestUtil .registerProcedure (db , Jdbc .class );
42
+ TestUtil .registerProcedure (db , Jdbc .class , Periodic . class );
40
43
}
41
44
42
45
@ AfterClass
@@ -54,6 +57,11 @@ public void testLoadJdbc() {
54
57
public void testIssue3496 () {
55
58
MySQLJdbcTest .testIssue3496 (db , mysql );
56
59
}
60
+
61
+ @ Test
62
+ public void testWithPeriodicRepeat () {
63
+ MySQLJdbcTest .testPeriodicRepeat (db , mysql );
64
+ }
57
65
}
58
66
59
67
public static class MySQLJdbcFiveVersionTest {
@@ -67,7 +75,7 @@ public static class MySQLJdbcFiveVersionTest {
67
75
@ BeforeClass
68
76
public static void setUpContainer () {
69
77
mysql .start ();
70
- TestUtil .registerProcedure (db , Jdbc .class );
78
+ TestUtil .registerProcedure (db , Jdbc .class , Periodic . class );
71
79
}
72
80
73
81
@ AfterClass
@@ -85,8 +93,57 @@ public void testLoadJdbc() {
85
93
public void testIssue3496 () {
86
94
MySQLJdbcTest .testIssue3496 (db , mysql );
87
95
}
96
+
97
+ @ Test
98
+ public void testWithPeriodicRepeat () {
99
+ MySQLJdbcTest .testPeriodicRepeat (db , mysql );
100
+ }
88
101
}
102
+
103
+
104
+ private static void testPeriodicRepeat (DbmsRule db , MySQLContainerExtension mysql ) {
105
+ String url = mysql .getJdbcUrl ();
106
+
107
+ String sqlQuery = "insert ignore into merchandise_id (id, source) values ('112233', 'Example Data 112233')" ;
108
+ String query = """
109
+ call apoc.periodic.repeat(
110
+ '000. test',
111
+ 'call apoc.load.jdbcUpdate(
112
+ $url,
113
+ $sqlQuery,
114
+ [],
115
+ {credentials: {user: $user, password: $password}}) YIELD row',
116
+ 1,
117
+ { params: $params }
118
+ );
119
+ """ ;
89
120
121
+ db .executeTransactionally (
122
+ query ,
123
+ Util .map ("params" , Util .map (
124
+ "url" , url ,
125
+ "sqlQuery" , sqlQuery ,
126
+ "user" , mysql .getUsername (),
127
+ "password" , mysql .getPassword ()
128
+ )),
129
+ Result ::resultAsString
130
+ );
131
+
132
+ testCallEventually (db , """
133
+ WITH $url as url
134
+ CALL apoc.load.jdbc(url, "merchandise_id", [], {credentials: {user: $user, password: $password}}) YIELD row
135
+ RETURN count(*);
136
+ """ ,
137
+ Util .map (
138
+ "url" , url ,
139
+ "user" , mysql .getUsername (),
140
+ "password" , mysql .getPassword ()
141
+ ),
142
+ (row ) -> assertEquals (2L , row .get ("count(*)" )),
143
+ 3
144
+ );
145
+ }
146
+
90
147
private static void testLoadJdbc (DbmsRule db , MySQLContainerExtension mysql ) {
91
148
// with the config {timezone: 'UTC'} and `preserveInstants=true&connectionTimeZone=SERVER` to make the result deterministic,
92
149
// since `TIMESTAMP` values are automatically converted from the session time zone to UTC for storage, and vice versa.
0 commit comments