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
@@ -28,15 +31,16 @@ public class MySQLJdbcTest extends AbstractJdbcTest {
28
31
public static class MySQLJdbcLatestVersionTest {
29
32
30
33
@ ClassRule
31
- public static MySQLContainerExtension mysql = new MySQLContainerExtension ("mysql:8.0.31" );
34
+ public static MySQLContainerExtension mysql = new MySQLContainerExtension ("mysql:8.0.31" )
35
+ .withInitScript ("init_mysql_script.sql" );
32
36
33
37
@ ClassRule
34
38
public static DbmsRule db = new ImpermanentDbmsRule ();
35
39
36
40
@ BeforeClass
37
41
public static void setUpContainer () {
38
42
mysql .start ();
39
- TestUtil .registerProcedure (db , Jdbc .class );
43
+ TestUtil .registerProcedure (db , Jdbc .class , Periodic . class );
40
44
}
41
45
42
46
@ AfterClass
@@ -54,6 +58,50 @@ public void testLoadJdbc() {
54
58
public void testIssue3496 () {
55
59
MySQLJdbcTest .testIssue3496 (db , mysql );
56
60
}
61
+
62
+ @ Test
63
+ public void testWithPeriodicRepeat () {
64
+ String url = mysql .getJdbcUrl ();
65
+
66
+ String sqlQuery = "insert ignore into merchandise_id (id, source) values ('112233', 'Example Data 112233')" ;
67
+ String query = """
68
+ call apoc.periodic.repeat(
69
+ '000. test',
70
+ 'call apoc.load.jdbcUpdate(
71
+ $url,
72
+ $sqlQuery,
73
+ [],
74
+ {credentials: {user: $user, password: $password}}) YIELD row',
75
+ 1,
76
+ { params: $params }
77
+ );
78
+ """ ;
79
+
80
+ db .executeTransactionally (
81
+ query ,
82
+ Util .map ("params" , Util .map (
83
+ "url" , url ,
84
+ "sqlQuery" , sqlQuery ,
85
+ "user" , mysql .getUsername (),
86
+ "password" , mysql .getPassword ()
87
+ )),
88
+ Result ::resultAsString
89
+ );
90
+
91
+ testCallEventually (db , """
92
+ WITH $url as url
93
+ CALL apoc.load.jdbc(url, "merchandise_id", [], {credentials: {user: $user, password: $password}}) YIELD row
94
+ RETURN count(*);
95
+ """ ,
96
+ Util .map (
97
+ "url" , url ,
98
+ "user" , mysql .getUsername (),
99
+ "password" , mysql .getPassword ()
100
+ ),
101
+ (row ) -> assertEquals (2L , row .get ("count(*)" )),
102
+ 3
103
+ );
104
+ }
57
105
}
58
106
59
107
public static class MySQLJdbcFiveVersionTest {
0 commit comments