/
OracleBulkDatabaseWriterTest.java
126 lines (105 loc) · 4.79 KB
/
OracleBulkDatabaseWriterTest.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
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jumpmind.symmetric.io;
import java.util.ArrayList;
import java.util.List;
import org.jumpmind.db.DbTestUtils;
import org.jumpmind.db.platform.oracle.OracleDatabasePlatform;
import org.jumpmind.db.util.BasicDataSourcePropertyConstants;
import org.jumpmind.symmetric.io.data.CsvData;
import org.jumpmind.symmetric.io.data.DataEventType;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor;
public class OracleBulkDatabaseWriterTest extends AbstractWriterTest {
@BeforeClass
public static void setup() throws Exception {
if (DbTestUtils.getEnvironmentSpecificProperties(DbTestUtils.ROOT)
.get(BasicDataSourcePropertyConstants.DB_POOL_DRIVER)
.equals("oracle.jdbc.driver.OracleDriver")) {
platform = DbTestUtils.createDatabasePlatform(DbTestUtils.ROOT);
platform.createDatabase(
platform.readDatabaseFromXml("/testOracleBulkWriter.xml", true), true, false);
}
}
@Before
public void setupTest() {
setErrorExpected(false);
}
@Override
protected long writeData(TableCsvData... datas) {
return writeData(new OracleBulkDatabaseWriter(platform, "sym",
new CommonsDbcpNativeJdbcExtractor(), 1000, null), datas);
}
@Override
protected String getTestTable() {
return "test_bulkload_table_1";
}
@Test
public void testInsert1000Rows() {
if (platform != null && platform instanceof OracleDatabasePlatform) {
platform.getSqlTemplate().update("truncate table test_bulkload_table_1");
List<CsvData> datas = new ArrayList<CsvData>();
for (int i = 0; i < 1000; i++) {
String[] values = { getNextId(), "string2", "string not null2", "char2",
"char not null2", "2007-01-02 03:20:10.000", "2007-02-03 04:05:06.000", "0",
"47", "67.89", "-0.0747663" };
CsvData data = new CsvData(DataEventType.INSERT, values);
datas.add(data);
}
long count = writeData(new TableCsvData(platform.getTableFromCache(
"test_bulkload_table_1", false), datas));
Assert.assertEquals(count, countRows("test_bulkload_table_1"));
}
}
@Test
public void testInsertCollision() {
if (platform != null && platform instanceof OracleDatabasePlatform) {
platform.getSqlTemplate().update("truncate table test_bulkload_table_1");
String[] values = { getNextId(), "string2", "string not null2", "char2",
"char not null2", "2007-01-02 03:20:10.000", "2007-02-03 04:05:06.000", "0", "47",
"67.89", "-0.0747663" };
CsvData data = new CsvData(DataEventType.INSERT, values);
writeData(data, values);
Assert.assertEquals(1, countRows("test_bulkload_table_1"));
try {
setErrorExpected(true);
List<CsvData> datas = new ArrayList<CsvData>();
datas.add(data);
for (int i = 0; i < 10; i++) {
values = new String[] { getNextId(), "string2", "string not null2", "char2",
"char not null2", "2007-01-02 03:20:10.000", "2007-02-03 04:05:06.000",
"0", "47", "67.89", "-0.0747663" };
data = new CsvData(DataEventType.INSERT, values);
datas.add(data);
}
// we should collide and rollback
writeData(new TableCsvData(platform.getTableFromCache("test_bulkload_table_1",
false), datas));
Assert.assertEquals(1, countRows("test_bulkload_table_1"));
} finally {
setErrorExpected(false);
}
}
}
}