Skip to content

Commit 09ace96

Browse files
exceptionfactorypvillard31
authored andcommitted
NIFI-15398 Replaced Apache Derby with HSQLDB
- Added Embedded Database Service module with shared implementation for testing - Added Apache Derby to banned dependencies - Removed Apache Derby dependencies Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #10703.
1 parent a316f16 commit 09ace96

35 files changed

Lines changed: 472 additions & 1094 deletions

File tree

‎nifi-code-coverage/pom.xml‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,6 @@
3434
<!-- Managed Dependency Versions for referenced modules required based on different parent bundle project -->
3535
<dependencyManagement>
3636
<dependencies>
37-
<!-- Apache Derby referenced in Hive and tests -->
38-
<dependency>
39-
<groupId>org.apache.derby</groupId>
40-
<artifactId>derbynet</artifactId>
41-
<version>${derby.version}</version>
42-
</dependency>
43-
<dependency>
44-
<groupId>org.apache.derby</groupId>
45-
<artifactId>derbytools</artifactId>
46-
<version>${derby.version}</version>
47-
</dependency>
48-
<dependency>
49-
<groupId>org.apache.derby</groupId>
50-
<artifactId>derbyclient</artifactId>
51-
<version>${derby.version}</version>
52-
</dependency>
5337
<!-- Apache Ant referenced in Groovy and Hive -->
5438
<dependency>
5539
<groupId>org.apache.ant</groupId>

‎nifi-extension-bundles/nifi-extension-utils/nifi-database-test-utils/pom.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222
</parent>
2323

2424
<artifactId>nifi-database-test-utils</artifactId>
25-
2625
</project>

‎nifi-extension-bundles/nifi-extension-utils/nifi-database-test-utils/src/main/java/org/apache/nifi/util/db/SimpleCommerceDataSet.java‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.apache.nifi.util.db;
1818

1919
import java.sql.Connection;
20-
import java.sql.DriverManager;
2120
import java.sql.SQLException;
2221
import java.sql.Statement;
2322
import java.util.Random;
@@ -103,10 +102,4 @@ static private String createRandomString() {
103102
}
104103
return new String(text);
105104
}
106-
107-
private Connection createConnection(String location) throws ClassNotFoundException, SQLException {
108-
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
109-
return DriverManager.getConnection("jdbc:derby:" + location + ";create=true");
110-
}
111-
112105
}

‎nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/pom.xml‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,8 @@
6565
<scope>test</scope>
6666
</dependency>
6767
<dependency>
68-
<groupId>org.apache.derby</groupId>
69-
<artifactId>derby</artifactId>
70-
<version>${derby.version}</version>
71-
<scope>test</scope>
72-
</dependency>
73-
<dependency>
74-
<groupId>org.apache.derby</groupId>
75-
<artifactId>derbytools</artifactId>
76-
<version>${derby.version}</version>
68+
<groupId>org.hsqldb</groupId>
69+
<artifactId>hsqldb</artifactId>
7770
<scope>test</scope>
7871
</dependency>
7972
</dependencies>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.nifi.util.db;
18+
19+
import org.junit.jupiter.api.BeforeAll;
20+
import org.junit.jupiter.api.io.TempDir;
21+
22+
import java.nio.file.Path;
23+
import java.sql.Connection;
24+
import java.sql.DriverManager;
25+
import java.sql.SQLException;
26+
27+
abstract class AbstractConnectionTest {
28+
private static final String DRIVER_CLASS = "org.hsqldb.jdbc.JDBCDriver";
29+
private static final String CONNECTION_URL_FORMAT = "jdbc:hsqldb:file:%s";
30+
31+
private static String connectionUrl;
32+
33+
@BeforeAll
34+
static void setConnectionUrl(@TempDir final Path tempDir) {
35+
try {
36+
Class.forName(DRIVER_CLASS);
37+
} catch (final ClassNotFoundException e) {
38+
throw new IllegalStateException("Driver Class [%s] not found".formatted(DRIVER_CLASS), e);
39+
}
40+
connectionUrl = CONNECTION_URL_FORMAT.formatted(tempDir);
41+
}
42+
43+
/**
44+
* Get SQL Connection from initialized temporary database location
45+
*
46+
* @return SQL Connection
47+
* @throws SQLException Thrown on connection retrieval failures
48+
*/
49+
protected Connection getConnection() throws SQLException {
50+
return DriverManager.getConnection(connectionUrl);
51+
}
52+
}

‎nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcClobReadable.java‎

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,21 @@
2020
import org.apache.avro.generic.GenericDatumReader;
2121
import org.apache.avro.generic.GenericRecord;
2222
import org.apache.avro.io.DatumReader;
23-
import org.apache.derby.jdbc.EmbeddedDriver;
24-
import org.apache.nifi.util.file.FileUtils;
25-
import org.junit.jupiter.api.AfterEach;
26-
import org.junit.jupiter.api.BeforeAll;
2723
import org.junit.jupiter.api.Test;
28-
import org.junit.jupiter.api.io.TempDir;
2924

3025
import java.io.ByteArrayInputStream;
3126
import java.io.ByteArrayOutputStream;
32-
import java.io.File;
3327
import java.io.IOException;
3428
import java.io.InputStream;
3529
import java.sql.Connection;
36-
import java.sql.DriverManager;
3730
import java.sql.ResultSet;
3831
import java.sql.SQLException;
3932
import java.sql.Statement;
4033

4134
import static org.junit.jupiter.api.Assertions.assertEquals;
4235
import static org.junit.jupiter.api.Assertions.assertNotNull;
43-
import static org.junit.jupiter.api.Assertions.assertThrows;
4436

45-
public class TestJdbcClobReadable {
46-
47-
private static final String DERBY_LOG_PROPERTY = "derby.stream.error.file";
48-
49-
@TempDir
50-
private static File tempDir;
51-
52-
@BeforeAll
53-
public static void setDerbyLog() {
54-
final File derbyLog = new File(tempDir, "derby.log");
55-
System.setProperty(DERBY_LOG_PROPERTY, derbyLog.getAbsolutePath());
56-
}
57-
58-
@AfterEach
59-
public void cleanup() throws IOException {
60-
if (folder != null && folder.exists()) {
61-
final SQLException exception = assertThrows(SQLException.class, () -> DriverManager.getConnection("jdbc:derby:;shutdown=true"));
62-
assertEquals("XJ015", exception.getSQLState());
63-
FileUtils.deleteFile(folder, true);
64-
}
65-
}
37+
class TestJdbcClobReadable extends AbstractConnectionTest {
6638

6739
String createTable = "create table users ("
6840
+ " id int NOT NULL GENERATED ALWAYS AS IDENTITY, "
@@ -74,38 +46,25 @@ public void cleanup() throws IOException {
7446
String dropTable = "drop table users";
7547

7648
@Test
77-
public void testClobWithChinese() throws SQLException, IOException, ClassNotFoundException {
49+
void testClobWithChinese() throws SQLException, IOException {
7850
String chineseContent = "中国China";
7951
validateClob(chineseContent);
8052
}
8153

8254
@Test
83-
public void testClobWithJapanese() throws SQLException, IOException, ClassNotFoundException {
55+
void testClobWithJapanese() throws SQLException, IOException {
8456
String japaneseContent = "にほんJapan";
8557
validateClob(japaneseContent);
8658
}
8759

8860
@Test
89-
public void testClobWithKorean() throws SQLException, IOException, ClassNotFoundException {
61+
void testClobWithKorean() throws SQLException, IOException {
9062
String koreanContent = "にほんKorea";
9163
validateClob(koreanContent);
9264
}
9365

94-
// many test use Derby as database, so ensure driver is available
95-
@Test
96-
public void testDriverLoad() throws ClassNotFoundException, SQLException {
97-
//Adding this because apparently the driver gets unloaded and unregistered
98-
DriverManager.registerDriver(new EmbeddedDriver());
99-
final Class<?> clazz = Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
100-
assertNotNull(clazz);
101-
}
102-
103-
private File folder;
104-
105-
private void validateClob(String someClob) throws SQLException, ClassNotFoundException, IOException {
106-
File topLevelTempDir = new File(tempDir, String.valueOf(System.currentTimeMillis()));
107-
folder = new File(topLevelTempDir, "db");
108-
final Connection con = createConnection(folder.getAbsolutePath());
66+
private void validateClob(String someClob) throws SQLException, IOException {
67+
final Connection con = getConnection();
10968
final Statement st = con.createStatement();
11069

11170
try {
@@ -143,10 +102,4 @@ record = dataFileReader.next(record);
143102
}
144103
}
145104
}
146-
147-
private Connection createConnection(String location) throws ClassNotFoundException, SQLException {
148-
DriverManager.registerDriver(new EmbeddedDriver());
149-
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
150-
return DriverManager.getConnection("jdbc:derby:" + location + ";create=true");
151-
}
152105
}

0 commit comments

Comments
 (0)