-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for UNKNOWN DATABASE
exception
#344
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50392ff
We get a `UNKNOWN DATABASE` exception because a connection string use…
9aa57f3
Added tests, small fixes.
IlyaTsoi e3dc37f
Merge branch 'develop' into fix_create_database
subkanthi 7ed46e9
Added @BeforeEach to dropTestDatabase()
IlyaTsoi 9e19fb3
Merge branch 'fix_create_database' of https://github.com/IlyaTsoi/cli…
IlyaTsoi 7353ef1
Small fixes
IlyaTsoi 223ba80
Revert "Small fixes"
IlyaTsoi 442e6ee
Small fixes
IlyaTsoi 7876bdd
Solved NullPointerException
IlyaTsoi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...va/com/altinity/clickhouse/sink/connector/db/operations/ClickHouseCreateDatabaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.altinity.clickhouse.sink.connector.db.operations; | ||
|
||
import com.altinity.clickhouse.sink.connector.ClickHouseSinkConnectorConfig; | ||
import com.clickhouse.jdbc.ClickHouseConnection; | ||
import com.clickhouse.jdbc.ClickHouseDataSource; | ||
import com.altinity.clickhouse.sink.connector.db.DbWriter; | ||
import org.junit.Assert; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.ClickHouseContainer; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.Properties; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
@Testcontainers | ||
|
||
public class ClickHouseCreateDatabaseTest { | ||
|
||
static DbWriter dbWriter; | ||
static DbWriter maintenanceDbWriter; | ||
static String dbName; | ||
|
||
@Container | ||
private ClickHouseContainer clickHouseContainer = new ClickHouseContainer("clickhouse/clickhouse-server:latest") | ||
.withInitScript("./init_clickhouse.sql");; | ||
@BeforeAll | ||
static void initialize() { | ||
|
||
String hostName = "localhost"; | ||
Integer port = 8123; | ||
String userName = "root"; | ||
String password = "root"; | ||
String systemDb = "system"; | ||
dbName = "test_create_db"; | ||
|
||
ClickHouseSinkConnectorConfig config= new ClickHouseSinkConnectorConfig(new HashMap<>()); | ||
dbWriter = new DbWriter(hostName, port, dbName, null, userName, password, config, null); | ||
maintenanceDbWriter = new DbWriter(hostName, port, systemDb, null, userName, password, config, null); | ||
} | ||
|
||
@Test | ||
public void testCreateNewDatabase() throws SQLException { | ||
this.dropTestDatabase(dbName); | ||
ClickHouseCreateDatabase act = new ClickHouseCreateDatabase(); | ||
ClickHouseConnection conn = dbWriter.getConnection(); | ||
try { | ||
act.createNewDatabase(conn, dbName); | ||
} catch(SQLException se) { | ||
//System.out.println(se.getMessage()); | ||
Assert.assertTrue(false); | ||
} | ||
Statement stmt = dbWriter.getConnection().createStatement(); | ||
String query = String.format("SELECT name FROM system.databases WHERE name = '%s'", dbName); | ||
ResultSet rs = stmt.executeQuery(query); | ||
Assert.assertTrue(rs.next()); | ||
} | ||
|
||
public void dropTestDatabase(String db) throws SQLException { | ||
Statement drop = maintenanceDbWriter.getConnection().createStatement(); | ||
drop.executeQuery(String.format("DROP DATABASE IF EXISTS %s", db)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra semicolon