/
SimpleIntegrationTest.java
1431 lines (1189 loc) · 59.6 KB
/
SimpleIntegrationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.jumpmind.symmetric.test;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Date;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.jumpmind.db.model.Table;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.TestConstants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.db.ISymmetricDialect;
import org.jumpmind.symmetric.model.NodeChannel;
import org.jumpmind.symmetric.model.NodeSecurity;
import org.jumpmind.symmetric.model.NodeStatus;
import org.jumpmind.symmetric.model.OutgoingBatches;
import org.jumpmind.symmetric.service.IConfigurationService;
import org.jumpmind.symmetric.service.IDataService;
import org.jumpmind.symmetric.service.IIncomingBatchService;
import org.jumpmind.symmetric.service.INodeService;
import org.jumpmind.symmetric.service.IOutgoingBatchService;
import org.jumpmind.symmetric.service.IParameterService;
import org.jumpmind.symmetric.statistic.IStatisticManager;
import org.jumpmind.symmetric.util.AppUtils;
import org.junit.Assert;
import org.junit.Test;
public class SimpleIntegrationTest extends AbstractIntegrationTest {
static final String THIS_IS_A_TEST = "This is a test";
public static boolean testFlag = false;
static final String updateOrderHeaderStatusSql = "update test_order_header set status = ? where order_id = ?";
static final String insertStoreStatusSql = "insert into test_store_status (store_id, register_id, status) values(?,?,?)";
static final String updateStoreStatusSql = "update test_store_status set status = ? where store_id = ? and register_id = ?";
static final String selectStoreStatusSql = "select status from test_store_status where store_id = ? and register_id = ?";
static final String enableKeyWordTriggerSql = "update sym_trigger set sync_on_insert = 1, sync_on_update = 1, sync_on_delete = 1 where source_table_name = 'test_key_word'";
static final String alterKeyWordSql = "alter table test_key_word add \"key word\" char(1)";
static final String alterKeyWordSql2 = "alter table test_key_word add \"case\" char(1)";
static final String insertKeyWordSql = "insert into test_key_word (id, \"key word\", \"case\") values (?, ?, ?)";
static final String updateKeyWordSql = "update test_key_word set \"key word\" = ?, \"case\" = ? where id = ?";
static final String selectKeyWordSql = "select \"key word\", \"case\" from test_key_word where id = ?";
static final String nullSyncColumnLevelSql = "update test_sync_column_level set string_value = null, time_value = null, date_value = null, bigint_value = null, decimal_value = null where id = ?";
static final String deleteSyncColumnLevelSql = "delete from test_sync_column_level where id = ?";
static final String updateSyncColumnLevelSql = "update test_sync_column_level set $(column) = ? where id = ?";
static final String selectSyncColumnLevelSql = "select count(*) from test_sync_column_level where id = ? and $(column) = ?";
static final String isRegistrationClosedSql = "select count(*) from sym_node_security where registration_enabled=0 and node_id=?";
static final String makeHeartbeatOld = "update sym_node set heartbeat_time={ts '2000-01-01 01:01:01.000'} where node_id=?";
static final String deleteNode = "delete from sym_node where node_id=?";
static final byte[] BINARY_DATA = new byte[] { 0x01, 0x02, 0x03 };
@Test(timeout = 120000)
public void createServer() {
ISymmetricEngine server = getServer();
Assert.assertNotNull(server);
checkForFailedTriggers(true, false);
}
@Test(timeout = 120000)
public void registerClientWithRoot() {
logTestRunning();
ISymmetricEngine rootEngine = getServer();
INodeService rootNodeService = rootEngine.getNodeService();
rootEngine.openRegistration(TestConstants.TEST_CLIENT_NODE_GROUP,
TestConstants.TEST_CLIENT_EXTERNAL_ID);
Assert.assertTrue("The registration for the client should be opened now", rootNodeService
.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isRegistrationEnabled());
getClient().start();
clientPull();
Assert.assertTrue("The client did not register", getClient().isRegistered());
Assert.assertFalse("The registration for the client should be closed now", rootNodeService
.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isRegistrationEnabled());
IStatisticManager statMgr = getClient().getStatisticManager();
statMgr.flush();
checkForFailedTriggers(true, true);
}
@Test(timeout = 120000)
public void initialLoad() {
logTestRunning();
serverTestService.insertIntoTestUseStreamLob(100, "test_use_stream_lob", THIS_IS_A_TEST);
serverTestService.insertIntoTestUseStreamLob(100, "test_use_capture_lob", THIS_IS_A_TEST);
Customer customer = new Customer(301, "Linus", true, "42 Blanket Street", "Santa Claus",
"IN", 90009, new Date(), new Date(), THIS_IS_A_TEST, BINARY_DATA);
serverTestService.insertCustomer(customer);
serverTestService.insertIntoTestTriggerTable(new Object[] { 1, "wow", "mom" });
serverTestService.insertIntoTestTriggerTable(new Object[] { 2, "mom", "wow" });
INodeService rootNodeService = getServer().getNodeService();
INodeService clientNodeService = getClient().getNodeService();
String nodeId = rootNodeService.findNodeByExternalId(TestConstants.TEST_CLIENT_NODE_GROUP,
TestConstants.TEST_CLIENT_EXTERNAL_ID).getNodeId();
getServer().reloadNode(nodeId);
IOutgoingBatchService rootOutgoingBatchService = getServer().getOutgoingBatchService();
Assert.assertFalse(rootOutgoingBatchService.isInitialLoadComplete(nodeId));
Assert.assertTrue(rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID)
.isInitialLoadEnabled());
do {
clientPull();
} while (!rootOutgoingBatchService.isInitialLoadComplete(nodeId));
Assert.assertFalse(rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID)
.isInitialLoadEnabled());
NodeSecurity clientNodeSecurity = clientNodeService
.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID);
Assert.assertFalse(clientNodeSecurity.isInitialLoadEnabled());
Assert.assertNotNull(clientNodeSecurity.getInitialLoadTime());
IIncomingBatchService clientIncomingBatchService = getClient().getIncomingBatchService();
Assert.assertEquals("The initial load errored out." + printRootAndClientDatabases(), 0,
clientIncomingBatchService.countIncomingBatchesInError());
Assert.assertEquals(
"test_triggers_table on the client did not contain the expected number of rows", 2,
clientTestService.countTestTriggersTable());
Assert.assertEquals(
"test_customer on the client did not contain the expected number of rows", 2,
clientTestService.count("test_customer"));
Assert.assertEquals("Initial load was not successful according to the client",
NodeStatus.DATA_LOAD_COMPLETED, clientNodeService.getNodeStatus());
Assert.assertEquals("Initial load was not successful accordign to the root", false,
rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID)
.isInitialLoadEnabled());
clientTestService.assertTestUseStreamBlobInDatabase(100, "test_use_stream_lob",
THIS_IS_A_TEST, getServer().getSymmetricDialect().getPlatform().getName());
clientTestService.assertTestUseStreamBlobInDatabase(100, "test_use_capture_lob",
THIS_IS_A_TEST, getServer().getSymmetricDialect().getPlatform().getName());
}
@Test(timeout = 120000)
public void syncToClient() {
logTestRunning();
// test pulling no data
clientPull();
final byte[] BIG_BINARY = new byte[200];
for (int i = 0; i < BIG_BINARY.length; i++) {
BIG_BINARY[i] = 0x01;
}
final String TEST_CLOB = "This is my test's test";
// now change some data that should be sync'd
Customer customer = new Customer(101, "Charlie Brown", true,
"300 Grub Street \\o", "New Yorl", "NY", 90009, new Date(), new Date(), TEST_CLOB,
BIG_BINARY);
serverTestService.insertCustomer(customer);
clientPull();
Assert.assertTrue("The customer was not sync'd to the client."
+ printRootAndClientDatabases(), clientTestService.doesCustomerExist(101));
Assert.assertEquals("The customer address was incorrect"
+ printRootAndClientDatabases(), customer.getAddress(), clientTestService.getCustomer(101).getAddress());
if (getServer().getSymmetricDialect().isClobSyncSupported()) {
Assert.assertEquals("The CLOB notes field on customer was not sync'd to the client",
serverTestService.getCustomerNotes(101),
clientTestService.getCustomerNotes(101));
}
if (getServer().getSymmetricDialect().isBlobSyncSupported()) {
byte[] data = clientTestService.getCustomerIcon(101);
Assert.assertTrue("The BLOB icon field on customer was not sync'd to the client",
ArrayUtils.isEquals(data, BIG_BINARY));
}
}
@Test(timeout = 120000)
public void syncToClientMultipleUpdates() {
logTestRunning();
// test pulling no data
clientPull();
final int NEW_ZIP = 44444;
final String NEW_NAME = "JoJo Duh Doh";
// now change some data that should be sync'd
serverTestService.updateCustomer(100, "zip", NEW_ZIP, Types.NUMERIC);
serverTestService.updateCustomer(100, "name", NEW_NAME, Types.VARCHAR);
boolean didPullData = clientPull();
Assert.assertTrue(didPullData);
Customer clientCustomer = clientTestService.getCustomer(100);
Assert.assertEquals(NEW_ZIP, clientCustomer.getZip());
Assert.assertEquals(NEW_NAME, clientCustomer.getName());
}
@Test(timeout = 120000)
public void testInsertSqlEvent() {
Assert.assertTrue(getClient().getSqlTemplate().queryForInt(
"select count(*) from sym_node where schema_version='test'") == 0);
getServer()
.getDataService().insertSqlEvent(TestConstants.TEST_CLIENT_NODE,
"update sym_node set schema_version='test'", false);
clientPull();
Assert.assertTrue(getClient().getSqlTemplate().queryForInt(
"select count(*) from sym_node where schema_version='test'") > 0);
}
@Test(timeout = 120000)
public void testEmptyNullLob() {
Customer customer = new Customer(300, "Eric", true, "100 Main Street", "Columbus", "OH",
43082, new Date(), new Date(), "", new byte[0]);
serverTestService.insertCustomer(customer);
clientPull();
if (getServer().getSymmetricDialect().isClobSyncSupported()) {
if (isClientInterbase()) {
// Putting an empty string into a CLOB on Interbase results in a
// NULL value
Assert.assertNull("Expected null CLOB", clientTestService.getCustomerNotes(300));
} else {
Assert.assertEquals("Expected empty CLOB", serverTestService.getCustomerNotes(300),
clientTestService.getCustomerNotes(300));
}
}
if (getServer().getSymmetricDialect().isBlobSyncSupported()) {
Assert.assertArrayEquals("Expected empty BLOB", serverTestService.getCustomerIcon(300),
clientTestService.getCustomerIcon(300));
}
Table table = getServer().getSymmetricDialect().getPlatform()
.getTableFromCache("test_customer", false);
// Test null large object
serverTestService.updateCustomer(300, "notes", null, table.getColumnWithName("notes")
.getMappedTypeCode());
serverTestService.updateCustomer(300, "icon", null, table.getColumnWithName("icon")
.getMappedTypeCode());
clientPull();
if (getServer().getSymmetricDialect().isClobSyncSupported()) {
Assert.assertNull("Expected null CLOB", clientTestService.getCustomerNotes(300));
}
if (getServer().getSymmetricDialect().isBlobSyncSupported()) {
Assert.assertNull("Expected null BLOB", clientTestService.getCustomerIcon(300));
}
}
@Test(timeout = 120000)
public void testLargeLob() {
if (!isServerOracle()) {
return;
}
String bigString = StringUtils.rightPad("Feeling tired... ", 6000, "Z");
Customer customer = new Customer(400, "Eric", true, "100 Main Street", "Columbus", "OH",
43082, new Date(), new Date(), bigString, bigString.getBytes());
serverTestService.insertCustomer(customer);
clientPull();
}
@Test(timeout = 120000)
public void testSuspendIgnorePushRemoteBatches() throws Exception {
// test suspend / ignore with remote database specifying the suspends
// and ignores
logTestRunning();
Date date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
Order order = new Order("101", 100, null, date);
order.getOrderDetails().add(
new OrderDetail("101", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
Assert.assertNull(serverTestService.getOrder(order.getOrderId()));
clientTestService.insertOrder(order);
boolean pushedData = clientPush();
Assert.assertTrue("Client data was not batched and pushed", pushedData);
Assert.assertNotNull(serverTestService.getOrder(order.getOrderId()));
IConfigurationService rootConfigurationService = getServer().getConfigurationService();
IOutgoingBatchService clientOutgoingBatchService = getClient().getOutgoingBatchService();
NodeChannel c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(true);
rootConfigurationService.saveNodeChannel(c, true);
date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
order = new Order("102", 100, null, date);
order.getOrderDetails().add(
new OrderDetail("102", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
Assert.assertNull(serverTestService.getOrder(order.getOrderId()));
clientTestService.insertOrder(order);
clientPush();
OutgoingBatches batches = clientOutgoingBatchService.getOutgoingBatches(
TestConstants.TEST_ROOT_NODE, false);
Assert.assertEquals("There should be one outgoing batches.", 1, batches.getBatches().size());
Assert.assertNull("The order record was synchronized when it should not have been",
serverTestService.getOrder(order.getOrderId()));
c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setIgnoreEnabled(true);
rootConfigurationService.saveNodeChannel(c, true);
clientPush();
batches = clientOutgoingBatchService
.getOutgoingBatches(TestConstants.TEST_ROOT_NODE, false);
Assert.assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
Assert.assertNull("The order record was synchronized when it should not have been",
serverTestService.getOrder(order.getOrderId()));
// Cleanup!
c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(false);
c.setIgnoreEnabled(false);
rootConfigurationService.saveNodeChannel(c, true);
clientPush();
}
@Test(timeout = 120000)
public void testSuspendIgnorePushLocalBatches() throws Exception {
// test suspend / ignore with local database specifying the suspends
// and ignores
logTestRunning();
Date date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
Order order = new Order("105", 100, null, date);
order.getOrderDetails().add(
new OrderDetail("105", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
Assert.assertNull(serverTestService.getOrder(order.getOrderId()));
clientTestService.insertOrder(order);
clientPush();
Assert.assertNotNull(serverTestService.getOrder(order.getOrderId()));
IConfigurationService clientConfigurationService = getClient().getConfigurationService();
IOutgoingBatchService clientOutgoingBatchService = getClient().getOutgoingBatchService();
NodeChannel c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(true);
clientConfigurationService.saveNodeChannel(c, true);
order = new Order("106", 100, null, date);
order.getOrderDetails().add(
new OrderDetail("106", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
clientPush();
OutgoingBatches batches = clientOutgoingBatchService.getOutgoingBatches(
TestConstants.TEST_ROOT_NODE, false);
Assert.assertEquals("There should be no outgoing batches since suspended locally", 0,
batches.getBatches().size());
Assert.assertNull(serverTestService.getOrder(order.getOrderId()));
c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setIgnoreEnabled(true);
clientConfigurationService.saveNodeChannel(c, true);
clientPush();
batches = clientOutgoingBatchService
.getOutgoingBatches(TestConstants.TEST_ROOT_NODE, false);
Assert.assertEquals("There should be no outgoing batches since suspended locally", 0,
batches.getBatches().size());
Assert.assertNull(serverTestService.getOrder(order.getOrderId()));
// Cleanup!
c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(false);
c.setIgnoreEnabled(false);
clientConfigurationService.saveNodeChannel(c, true);
clientPush();
}
@Test(timeout = 120000)
public void testSuspendIgnorePullRemoteBatches() throws Exception {
// test suspend / ignore with remote database specifying the suspends
// and ignores
logTestRunning();
// Should not sync when status = null
Date date = DateUtils.parseDate("2009-09-30", new String[] { "yyyy-MM-dd" });
Order order = new Order("42", 100, "C", date);
serverTestService.insertOrder(order);
clientPull();
IOutgoingBatchService rootOutgoingBatchService = getServer().getOutgoingBatchService();
OutgoingBatches batches = rootOutgoingBatchService.getOutgoingBatches(
TestConstants.TEST_CLIENT_NODE, false);
Assert.assertNotNull(clientTestService.getOrder(order.getOrderId()));
Assert.assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
// Suspend the channel...
IConfigurationService rootConfigurationService = getServer().getConfigurationService();
NodeChannel c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(true);
rootConfigurationService.saveNodeChannel(c, true);
date = DateUtils.parseDate("2009-09-30", new String[] { "yyyy-MM-dd" });
order = new Order("43", 100, "C", date);
serverTestService.insertOrder(order);
clientPull();
batches = rootOutgoingBatchService
.getOutgoingBatches(TestConstants.TEST_CLIENT_NODE, false);
Assert.assertEquals("There should be 1 outgoing batch", 1, batches.getBatches().size());
Assert.assertNull(clientTestService.getOrder(order.getOrderId()));
c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setIgnoreEnabled(true);
rootConfigurationService.saveNodeChannel(c, true);
// ignore
clientPull();
batches = rootOutgoingBatchService
.getOutgoingBatches(TestConstants.TEST_CLIENT_NODE, false);
Assert.assertNull(clientTestService.getOrder(order.getOrderId()));
Assert.assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
// Cleanup!
c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(false);
c.setIgnoreEnabled(false);
rootConfigurationService.saveNodeChannel(c, true);
clientPull();
batches = rootOutgoingBatchService
.getOutgoingBatches(TestConstants.TEST_CLIENT_NODE, false);
Assert.assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
Assert.assertNull(clientTestService.getOrder(order.getOrderId()));
}
@Test(timeout = 120000)
public void testSuspendIgnorePullRemoteLocalComboBatches() throws Exception {
// test suspend / ignore with remote database specifying the suspends
// and ignores
logTestRunning();
Date date = DateUtils.parseDate("2009-09-30", new String[] { "yyyy-MM-dd" });
Order order = new Order("442", 100, "C", date);
serverTestService.insertOrder(order);
clientPull();
IOutgoingBatchService rootOutgoingBatchService = getServer().getOutgoingBatchService();
OutgoingBatches batches = rootOutgoingBatchService.getOutgoingBatches(
TestConstants.TEST_CLIENT_NODE, false);
Assert.assertNotNull(clientTestService.getOrder(order.getOrderId()));
Assert.assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
IConfigurationService rootConfigurationService = getServer().getConfigurationService();
IConfigurationService clientConfigurationService = getClient().getConfigurationService();
// suspend on remote
NodeChannel c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(true);
rootConfigurationService.saveNodeChannel(c, true);
// ignore on local
c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setIgnoreEnabled(true);
clientConfigurationService.saveNodeChannel(c, true);
order = new Order("443", 100, "C", date);
serverTestService.insertOrder(order);
clientPull();
batches = rootOutgoingBatchService
.getOutgoingBatches(TestConstants.TEST_CLIENT_NODE, false);
Assert.assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
Assert.assertNull(clientTestService.getOrder(order.getOrderId()));
// ignore on remote
c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setIgnoreEnabled(true);
c.setSuspendEnabled(false);
rootConfigurationService.saveNodeChannel(c, true);
// suspend on local
c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setIgnoreEnabled(false);
c.setSuspendEnabled(true);
clientConfigurationService.saveNodeChannel(c, true);
order = new Order("444", 100, "C", date);
clientPull();
batches = rootOutgoingBatchService
.getOutgoingBatches(TestConstants.TEST_CLIENT_NODE, false);
Assert.assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
Assert.assertNull(clientTestService.getOrder(order.getOrderId()));
// Cleanup!
c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(false);
c.setIgnoreEnabled(false);
rootConfigurationService.saveNodeChannel(c, true);
c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(false);
c.setIgnoreEnabled(false);
clientConfigurationService.saveNodeChannel(c, true);
clientPull();
}
@Test(timeout = 120000)
public void testUpdateDataWithNoChangesSyncToClient() throws Exception {
int clientIncomingBatchCount = getIncomingBatchCountForClient();
int rowsUpdated = getServer().getSqlTemplate().update(
"update test_sync_column_level set string_value=string_value");
Assert.assertTrue(rowsUpdated > 0);
clientPull();
Assert.assertTrue(clientIncomingBatchCount <= getIncomingBatchCountForClient());
Assert.assertEquals(0, getIncomingBatchNotOkCountForClient());
Assert.assertEquals(0, getServer().getOutgoingBatchService().countOutgoingBatchesInError());
Assert.assertEquals(serverTestService.count("test_sync_column_level"),
clientTestService.count("test_sync_column_level"));
}
@Test(timeout = 120000)
public void testSuspendIgnorePullLocalBatches() throws Exception {
// test suspend / ignore with local database specifying suspends and
// ignores
logTestRunning();
// Should not sync when status = null
Date date = DateUtils.parseDate("2009-09-30", new String[] { "yyyy-MM-dd" });
Order order = new Order("44", 100, "C", date);
serverTestService.insertOrder(order);
clientPull();
IOutgoingBatchService rootOutgoingBatchService = getServer().getOutgoingBatchService();
OutgoingBatches batches = rootOutgoingBatchService.getOutgoingBatches(
TestConstants.TEST_CLIENT_NODE, false);
Assert.assertNotNull(clientTestService.getOrder(order.getOrderId()));
Assert.assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
// Suspend the channel...
IConfigurationService clientConfigurationService = getClient().getConfigurationService();
NodeChannel c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(true);
clientConfigurationService.saveNodeChannel(c, true);
order = new Order("45", 100, "C", date);
serverTestService.insertOrder(order);
clientPull();
batches = rootOutgoingBatchService
.getOutgoingBatches(TestConstants.TEST_CLIENT_NODE, false);
Assert.assertNull(clientTestService.getOrder(order.getOrderId()));
Assert.assertEquals("There should be 1 outgoing batches", 1, batches.getBatches().size());
c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setIgnoreEnabled(true);
clientConfigurationService.saveNodeChannel(c, true);
// ignore
clientPull();
assertNoPendingBatchesOnServer();
c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
c.setSuspendEnabled(false);
c.setIgnoreEnabled(false);
clientConfigurationService.saveNodeChannel(c, true);
clientPull();
}
@Test(timeout = 120000)
public void syncToRootAutoGeneratedPrimaryKey() {
logTestRunning();
final String NEW_VALUE = "unique new value one value";
clientTestService
.insertIntoTestTriggerTable(new Object[] { 3, "value one", "value \" two" });
clientPush();
getClient().getSqlTemplate().update("update test_triggers_table set string_one_value=?",
NEW_VALUE);
final String verifySql = "select count(*) from test_triggers_table where string_one_value=?";
Assert.assertEquals(3, getClient().getSqlTemplate().queryForInt(verifySql, NEW_VALUE));
clientPush();
Assert.assertEquals(3, getServer().getSqlTemplate().queryForInt(verifySql, NEW_VALUE));
}
@Test(timeout = 120000)
public void reopenRegistration() {
logTestRunning();
getServer().reOpenRegistration(TestConstants.TEST_CLIENT_EXTERNAL_ID);
clientPull();
Assert.assertEquals(
1,
getServer().getSqlTemplate().queryForInt(isRegistrationClosedSql,
TestConstants.TEST_CLIENT_EXTERNAL_ID));
}
@Test(timeout = 120000)
public void syncToRoot() throws Exception {
logTestRunning();
Date date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
Order order = new Order("10", 100, null, date);
order.getOrderDetails().add(
new OrderDetail("10", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
clientTestService.insertOrder(order);
Assert.assertNull(serverTestService.getOrder(order.getOrderId()));
clientPush();
Assert.assertNotNull(serverTestService.getOrder(order.getOrderId()));
}
@Test(timeout = 120000)
public void syncInsertCondition() throws Exception {
logTestRunning();
// Should not sync when status = null
Date date = DateUtils.parseDate("2007-01-02", new String[] { "yyyy-MM-dd" });
Order order = new Order("11", 100, null, date);
serverTestService.insertOrder(order);
clientPull();
assertNoPendingBatchesOnServer();
Assert.assertNull(clientTestService.getOrder(order.getOrderId()));
// Should sync when status = C
order = new Order("12", 100, "C", date);
serverTestService.insertOrder(order);
clientPull();
Assert.assertNotNull(clientTestService.getOrder(order.getOrderId()));
}
@Test(timeout = 120000)
public void oneColumnTableWithPrimaryKeyUpdate() throws Exception {
logTestRunning();
getServer().getSqlTemplate().update("insert into one_column_table values(1)");
Assert.assertTrue(getClient().getSqlTemplate().queryForInt(
"select count(*) from one_column_table where my_one_column=1") == 0);
clientPull();
Assert.assertTrue(getClient().getSqlTemplate().queryForInt(
"select count(*) from one_column_table where my_one_column=1") == 1);
getServer().getSqlTemplate().update(
"update one_column_table set my_one_column=1 where my_one_column=1");
clientPull();
assertNoPendingBatchesOnServer();
}
@Test(timeout = 120000)
public void syncUpdateCondition() {
logTestRunning();
Order order = clientTestService.getOrder("1");
Assert.assertNull(order);
getServer().getSqlTemplate().update(updateOrderHeaderStatusSql, "C", "1");
clientPull();
order = clientTestService.getOrder("1");
Assert.assertNotNull(order);
Assert.assertEquals("C", order.getStatus());
}
@Test(timeout = 120000)
public void ignoreNodeChannel() {
logTestRunning();
INodeService rootNodeService = getServer().getNodeService();
IConfigurationService rootConfigService = getServer().getConfigurationService();
rootNodeService.ignoreNodeChannelForExternalId(true, TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_ROOT_NODE_GROUP, TestConstants.TEST_ROOT_EXTERNAL_ID);
rootConfigService.reloadChannels();
NodeChannel channel = rootConfigService.getNodeChannel(TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_ROOT_EXTERNAL_ID, false);
Assert.assertNotNull(channel);
Assert.assertTrue(channel.isIgnoreEnabled());
Assert.assertFalse(channel.isSuspendEnabled());
Customer customer = new Customer(201, "Charlie Dude", true, "300 Grub Street", "New York",
"NY", 90009, new Date(), new Date(), THIS_IS_A_TEST, BINARY_DATA);
serverTestService.insertCustomer(customer);
clientPull();
Assert.assertNull(clientTestService.getCustomer(customer.getCustomerId()));
rootNodeService.ignoreNodeChannelForExternalId(false, TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_ROOT_NODE_GROUP, TestConstants.TEST_ROOT_EXTERNAL_ID);
rootConfigService.reloadChannels();
clientPull();
Assert.assertNull(clientTestService.getCustomer(customer.getCustomerId()));
getClient().getConfigurationService().reloadChannels();
}
@Test(timeout = 120000)
public void syncUpdateWithEmptyKey() {
logTestRunning();
try {
if (getClient().getSymmetricDialect().getPlatform().getDatabaseInfo()
.isEmptyStringNulled()) {
return;
}
getClient().getSqlTemplate().update(insertStoreStatusSql,
new Object[] { "00001", "", 1 });
clientPush();
getClient().getSqlTemplate().update(updateStoreStatusSql,
new Object[] { 2, "00001", "" });
clientPush();
int status = getServer().getSqlTemplate().queryForInt(selectStoreStatusSql,
new Object[] { "00001", " " });
Assert.assertEquals("Wrong store status", 2, status);
} finally {
logTestComplete();
}
}
@Test(timeout = 120000)
public void testPurge() throws Exception {
logTestRunning();
// do an extra push & pull to make sure we have events cleared out
clientPull();
clientPush();
Thread.sleep(2000);
IParameterService parameterService = getServer().getParameterService();
int purgeRetentionMinues = parameterService
.getInt(ParameterConstants.PURGE_RETENTION_MINUTES);
// set purge in the future just in case the database time is different
// than the current time
parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES, -60 * 24);
int beforePurge = getServer().getSqlTemplate().queryForInt("select count(*) from sym_data");
getServer().purge();
int afterPurge = getServer().getSqlTemplate().queryForInt("select count(*) from sym_data");
Timestamp maxCreateTime = (Timestamp) getServer().getSqlTemplate().queryForObject(
"select max(create_time) from sym_data", Timestamp.class);
Timestamp minCreateTime = (Timestamp) getServer().getSqlTemplate().queryForObject(
"select min(create_time) from sym_data", Timestamp.class);
Assert.assertTrue("Expected data rows to have been purged at the root. There were "
+ beforePurge + " row before and " + afterPurge
+ " rows after. The max create_time in sym_data was " + maxCreateTime
+ " and the min create_time in sym_data was " + minCreateTime
+ " and the current time of the server is " + new Date(),
(beforePurge - afterPurge) > 0);
parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES,
purgeRetentionMinues);
parameterService = getClient().getParameterService();
purgeRetentionMinues = parameterService.getInt(ParameterConstants.PURGE_RETENTION_MINUTES);
// set purge in the future just in case the database time is different
// than the current time
parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES, -60 * 24);
beforePurge = getClient().getSqlTemplate().queryForInt("select count(*) from sym_data");
getClient().purge();
afterPurge = getClient().getSqlTemplate().queryForInt("select count(*) from sym_data");
maxCreateTime = (Timestamp) getClient().getSqlTemplate().queryForObject(
"select max(create_time) from sym_data", Timestamp.class);
minCreateTime = (Timestamp) getClient().getSqlTemplate().queryForObject(
"select min(create_time) from sym_data", Timestamp.class);
Assert.assertTrue("Expected data rows to have been purged at the client. There were "
+ beforePurge + " row before anf " + afterPurge
+ " rows after. . The max create_time in sym_data was " + maxCreateTime
+ " and the min create_time in sym_data was " + minCreateTime
+ " and the current time of the server is " + new Date(),
(beforePurge - afterPurge) > 0);
parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES,
purgeRetentionMinues);
}
@Test(timeout = 120000)
public void testHeartbeat() throws Exception {
logTestRunning();
final String checkHeartbeatSql = "select heartbeat_time from sym_node where external_id='"
+ TestConstants.TEST_CLIENT_EXTERNAL_ID + "'";
Date clientHeartbeatTimeBefore = getClient().getSqlTemplate().queryForObject(
checkHeartbeatSql, Timestamp.class);
Thread.sleep(1000);
getClient().heartbeat(true);
Date clientHeartbeatTimeAfter = getClient().getSqlTemplate().queryForObject(
checkHeartbeatSql, Timestamp.class);
Assert.assertNotSame("The heartbeat time was not updated at the client",
clientHeartbeatTimeAfter, clientHeartbeatTimeBefore);
Date rootHeartbeatTimeBefore = getServer().getSqlTemplate().queryForObject(
checkHeartbeatSql, Timestamp.class);
Assert.assertNotSame(
"The root heartbeat time should not be the same as the updated client heartbeat time",
clientHeartbeatTimeAfter, rootHeartbeatTimeBefore);
while (clientPush()) {
// continue to push while there data to push
Thread.sleep(1000);
}
Date rootHeartbeatTimeAfter = getServer().getSqlTemplate().queryForObject(
checkHeartbeatSql, Timestamp.class);
Assert.assertEquals(
"The client heartbeat time should have been the same as the root heartbeat time.",
clientHeartbeatTimeAfter, rootHeartbeatTimeAfter);
}
@Test(timeout = 120000)
public void testVirtualTransactionId() {
logTestRunning();
getServer().getSqlTemplate().update(
"insert into test_very_long_table_name_1234 values('42')");
if (getServer().getSymmetricDialect().isTransactionIdOverrideSupported()) {
Assert.assertEquals(
"The hardcoded transaction id was not found.",
"42",
getServer()
.getSqlTemplate()
.queryForObject(
"select transaction_id from sym_data where data_id in (select max(data_id) from sym_data)",
String.class));
Assert.assertEquals(
1,
getServer().getSqlTemplate().update(
"delete from test_very_long_table_name_1234 where id='42'"));
Assert.assertEquals(
"The hardcoded transaction id was not found.",
"42",
getServer()
.getSqlTemplate()
.queryForObject(
"select transaction_id from sym_data where data_id in (select max(data_id) from sym_data)",
String.class));
}
}
@Test(timeout = 120000)
public void testCaseSensitiveTableNames() {
logTestRunning();
String rquote = getServer().getSymmetricDialect().getPlatform().getDatabaseInfo()
.getDelimiterToken();
String cquote = getClient().getSymmetricDialect().getPlatform().getDatabaseInfo()
.getDelimiterToken();
getServer().getSqlTemplate().update(
"insert into " + rquote + "Test_Mixed_Case" + rquote + " values(?,?)", 1, "Hello");
while (clientPull()) {
AppUtils.sleep(1000);
}
Assert.assertEquals(
"Table name in mixed case was not synced",
1,
getClient().getSqlTemplate().queryForInt(
"select count(*) from " + cquote + "Test_Mixed_Case" + cquote + " where "
+ cquote + "Mixed_Case_Id" + cquote + " = 1"));
}
@Test(timeout = 120000)
public void testSyncShellCommand() throws Exception {
logTestRunning();
IDataService rootDataService = getServer().getDataService();
IOutgoingBatchService rootOutgoingBatchService = getServer().getOutgoingBatchService();
testFlag = false;
String scriptData = "org.jumpmind.symmetric.test.SimpleIntegrationTest.testFlag=true;";
rootDataService.sendScript(TestConstants.TEST_CLIENT_EXTERNAL_ID, scriptData, false);
clientPull();
OutgoingBatches batches = rootOutgoingBatchService.getOutgoingBatches(
TestConstants.TEST_CLIENT_NODE, false);
Assert.assertEquals(0, batches.countBatches(true));
Assert.assertTrue("Expected the testFlag static variable to have been set to true", testFlag);
}
@Test
public void testAutoConfigureTablesAfterAlreadyCreated() {
testAutoConfigureTablesAfterAlreadyCreated(getServer());
testAutoConfigureTablesAfterAlreadyCreated(getClient());
}
protected void testAutoConfigureTablesAfterAlreadyCreated(ISymmetricEngine engine) {
ISymmetricDialect dialect = engine.getSymmetricDialect();
Assert.assertEquals("Tables were altered when they should not have been", false, dialect.createOrAlterTablesIfNecessary());
}