Support for MS SQL Server and RabbitMQ 3.7 (#656)

* SQL server support.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Complete SQL server setup.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* DB2 support.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Add new rabbit http client version.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Cleanup JDBC driver dependencies.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix test.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Complete test utils for MSSQL.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Add and fix comments

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix Javadoc

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Removed super constr call

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fixed merge bug.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove non null migrations. Won't work in production.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Added config profile for MS SQL server according to MySQL configuration

Signed-off-by: Dominic Schabel <dominic.schabel@bosch-si.com>

* Minor fix in status column

Signed-off-by: Dominic Schabel <dominic.schabel@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2018-03-13 16:41:10 +01:00
committed by GitHub
parent ab2305fa80
commit 1f43862618
55 changed files with 1516 additions and 388 deletions

View File

@@ -14,17 +14,13 @@ import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpre
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomStringUtils;
@@ -104,7 +100,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
// test execution. So, the order execution between EventVerifier and Cleanup is
// important!
@TestExecutionListeners(inheritListeners = true, listeners = { EventVerifier.class, CleanupTestExecutionListener.class,
MySqlTestDatabase.class }, mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
MySqlTestDatabase.class, MsSqlTestDatabase.class }, mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
public abstract class AbstractIntegrationTest {
private static final Logger LOG = LoggerFactory.getLogger(AbstractIntegrationTest.class);
@@ -378,24 +374,25 @@ public abstract class AbstractIntegrationTest {
*
* @return {@link String} containing a valid cron expression.
*/
public static String getTestSchedule(int minutesToAdd) {
public static String getTestSchedule(final int minutesToAdd) {
ZonedDateTime currentTime = ZonedDateTime.now();
currentTime = currentTime.plusMinutes(minutesToAdd);
return String.format("0 %d %d %d %d ? %d", currentTime.getMinute(), currentTime.getHour(),
currentTime.getDayOfMonth(), currentTime.getMonthValue(), currentTime.getYear());
}
public static String getTestDuration(int duration) {
public static String getTestDuration(final int duration) {
return String.format("%02d:%02d:00", duration / 60, duration % 60);
}
public static String getTestTimeZone() {
ZonedDateTime currentTime = ZonedDateTime.now();
final ZonedDateTime currentTime = ZonedDateTime.now();
return currentTime.getOffset().getId().replace("Z", "+00:00");
}
public static Map<String, String> getMaintenanceWindow(String schedule, String duration, String timezone) {
Map<String, String> maintenanceWindowMap = new HashMap<>();
public static Map<String, String> getMaintenanceWindow(final String schedule, final String duration,
final String timezone) {
final Map<String, String> maintenanceWindowMap = new HashMap<>();
maintenanceWindowMap.put("schedule", schedule);
maintenanceWindowMap.put("duration", duration);
maintenanceWindowMap.put("timezone", timezone);

View File

@@ -0,0 +1,95 @@
/**
* Copyright (c) 2018 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.test.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestExecutionListener;
import org.springframework.test.context.support.AbstractTestExecutionListener;
/**
* A {@link TestExecutionListener} for creating and dropping MS SQL Server
* schemas if tests are setup with MS SQL Server.
*/
public class MsSqlTestDatabase extends AbstractTestExecutionListener {
private static final Logger LOG = LoggerFactory.getLogger(MsSqlTestDatabase.class);
private String schemaName;
private String uri;
private String username;
private String password;
@Override
public void beforeTestClass(final TestContext testContext) throws Exception {
if (isRunningWithMsSql()) {
LOG.info("Setting up mysql schema for test class {}", testContext.getTestClass().getName());
this.username = System.getProperty("spring.datasource.username");
this.password = System.getProperty("spring.datasource.password");
this.uri = System.getProperty("spring.datasource.url");
createSchemaUri();
createSchema();
}
}
@Override
public void afterTestClass(final TestContext testContext) throws Exception {
if (isRunningWithMsSql()) {
dropSchema();
}
}
private void createSchemaUri() {
schemaName = "SP" + RandomStringUtils.randomAlphanumeric(10);
this.uri = this.uri.substring(0, uri.indexOf(';'));
System.setProperty("spring.datasource.url", uri + ";database=" + schemaName);
}
private static boolean isRunningWithMsSql() {
return "SQL_SERVER".equals(System.getProperty("spring.jpa.database"));
}
private void createSchema() {
try (Connection connection = DriverManager.getConnection(uri, username, password)) {
try (PreparedStatement statement = connection.prepareStatement("CREATE DATABASE " + schemaName + ";")) {
LOG.info("Creating schema {} on uri {}", schemaName, uri);
statement.execute();
LOG.info("Created schema {} on uri {}", schemaName, uri);
}
} catch (final SQLException e) {
LOG.error("Schema creation failed!", e);
}
}
private void dropSchema() {
try (Connection connection = DriverManager.getConnection(uri, username, password)) {
// Needed to avoid the DROP is rejected with "database still in use"
try (PreparedStatement statement = connection
.prepareStatement("ALTER DATABASE " + schemaName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE;")) {
statement.execute();
}
try (PreparedStatement statement = connection.prepareStatement("DROP DATABASE " + schemaName + ";")) {
LOG.info("Dropping schema {} on uri {}", schemaName, uri);
statement.execute();
LOG.info("Dropped schema {} on uri {}", schemaName, uri);
}
} catch (final SQLException e) {
LOG.error("Schema drop failed!", e);
}
}
}