Skip to content

Commit

Permalink
GEODE-7869: Cleanup warnings in geode-connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-at-work committed Mar 16, 2020
1 parent f098829 commit 4fb85db
Show file tree
Hide file tree
Showing 40 changed files with 310 additions and 262 deletions.
1 change: 1 addition & 0 deletions geode-connectors/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

apply from: "${rootDir}/${scriptDir}/standard-subproject-configuration.gradle"
apply from: "${project.projectDir}/../gradle/warnings.gradle"

evaluationDependsOn(":geode-core")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract class JdbcAsyncWriterIntegrationTest {
private static final String REGION_TABLE_NAME = "employees";

private InternalCache cache;
private Region<Object, PdxInstance> employees;
private Region<Object, Object> employees;
private Connection connection;
private Statement statement;
private JdbcAsyncWriter jdbcWriter;
Expand Down Expand Up @@ -136,8 +136,7 @@ public void verifyThatPdxFieldNamedSameAsPrimaryKeyIsIgnored() throws Exception
@Test
public void putNonPdxInstanceFails() throws RegionMappingExistsException {
setupRegion("id");
Region nonPdxEmployees = this.employees;
nonPdxEmployees.put("1", "non pdx instance");
employees.put("1", "non pdx instance");

awaitUntil(() -> assertThat(jdbcWriter.getTotalEvents()).isEqualTo(1));

Expand All @@ -148,9 +147,8 @@ public void putNonPdxInstanceFails() throws RegionMappingExistsException {
public void putNonPdxInstanceThatIsPdxSerializable()
throws SQLException, RegionMappingExistsException {
setupRegion("id");
Region nonPdxEmployees = this.employees;
Employee value = new Employee("2", "Emp2", 22);
nonPdxEmployees.put("2", value);
employees.put("2", value);

awaitUntil(() -> assertThat(jdbcWriter.getSuccessfulEvents()).isEqualTo(1));

Expand Down Expand Up @@ -324,13 +322,13 @@ private void assertRecordMatchesEmployee(ResultSet resultSet, String key, Employ
assertThat(resultSet.getObject("age")).isEqualTo(employee.getAge());
}

private Region<Object, PdxInstance> createRegionWithJDBCAsyncWriter(String regionName, String ids,
private Region<Object, Object> createRegionWithJDBCAsyncWriter(String regionName, String ids,
List<FieldMapping> fieldMappings)
throws RegionMappingExistsException {
jdbcWriter = new JdbcAsyncWriter(createSqlHandler(regionName, ids, fieldMappings), cache);
cache.createAsyncEventQueueFactory().setBatchSize(1).setBatchTimeInterval(1)
.create("jdbcAsyncQueue", jdbcWriter);
RegionFactory<Object, PdxInstance> regionFactory = cache.createRegionFactory(REPLICATE);
RegionFactory<Object, Object> regionFactory = cache.createRegionFactory(REPLICATE);
regionFactory.addAsyncEventQueueId("jdbcAsyncQueue");
return regionFactory.create(regionName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public abstract class JdbcWriterIntegrationTest {
protected static final String REGION_TABLE_NAME = "employees";

protected InternalCache cache;
protected Region<Object, PdxInstance> employees;
protected Region<Object, Object> employees;
protected Connection connection;
protected Statement statement;
protected JdbcWriter jdbcWriter;
protected JdbcWriter<Object, Object> jdbcWriter;
protected PdxInstance pdx1;
protected PdxInstance pdx2;
protected Employee employee1;
Expand Down Expand Up @@ -250,8 +250,7 @@ public void verifyThatPdxFieldNamedSameAsPrimaryKeyIsIgnored() throws Exception
public void putNonPdxInstanceFails() throws Exception {
createTable();
setupRegion("id");
Region nonPdxEmployees = this.employees;
Throwable thrown = catchThrowable(() -> nonPdxEmployees.put("1", "non pdx instance"));
Throwable thrown = catchThrowable(() -> employees.put("1", "non pdx instance"));
assertThat(thrown).isInstanceOf(IllegalArgumentException.class);
}

Expand All @@ -260,9 +259,8 @@ public void putNonPdxInstanceThatIsPdxSerializable()
throws SQLException, RegionMappingExistsException {
createTable();
setupRegion("id");
Region nonPdxEmployees = this.employees;
Employee value = new Employee("2", "Emp2", 22);
nonPdxEmployees.put("2", value);
employees.put("2", value);

ResultSet resultSet =
statement.executeQuery("select * from " + REGION_TABLE_NAME + " order by id asc");
Expand Down Expand Up @@ -404,13 +402,13 @@ public void canInsertBecomeUpdate() throws Exception {
assertThat(resultSet.next()).isFalse();
}

protected Region<Object, PdxInstance> createRegionWithJDBCSynchronousWriter(String regionName,
protected Region<Object, Object> createRegionWithJDBCSynchronousWriter(String regionName,
String ids, String catalog, String schema, List<FieldMapping> fieldMappings)
throws RegionMappingExistsException {
jdbcWriter =
new JdbcWriter(createSqlHandler(regionName, ids, catalog, schema, fieldMappings), cache);
new JdbcWriter<>(createSqlHandler(regionName, ids, catalog, schema, fieldMappings), cache);

RegionFactory<Object, PdxInstance> regionFactory =
RegionFactory<Object, Object> regionFactory =
cache.createRegionFactory(RegionShortcut.REPLICATE);
regionFactory.setCacheWriter(jdbcWriter);
return regionFactory.create(regionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.List;

import org.apache.geode.cache.Cache;
import org.apache.geode.connectors.jdbc.internal.configuration.FieldMapping;
import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping;
import org.apache.geode.internal.cache.InternalCache;
Expand Down Expand Up @@ -52,7 +53,9 @@ public static JdbcConnectorServiceImpl getTestConfigService(InternalCache cache,

private static InternalCache createMockCache() {
InternalCache cache = mock(InternalCache.class);
when(cache.getExtensionPoint()).thenReturn(mock(ExtensionPoint.class));
@SuppressWarnings("unchecked")
final ExtensionPoint<Cache> mockExtensionPoint = mock(ExtensionPoint.class);
when(cache.getExtensionPoint()).thenReturn(mockExtensionPoint);
return cache;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.rules.GfshCommandRule;
import org.apache.geode.test.junit.rules.VMProvider;
import org.apache.geode.util.test.TestUtil;
import org.apache.geode.test.util.ResourceUtils;

public class CreateDataSourceCommandDUnitTest {

Expand All @@ -59,16 +59,12 @@ public static void before() throws Exception {
}

@Test
public void testCreateDataSource() throws Exception {
public void testCreateDataSource() {
VMProvider.invokeInEveryMember(
() -> assertThat(JNDIInvoker.getNoOfAvailableDataSources()).isEqualTo(0), server1, server2);

String URL = "jdbc:derby:memory:newDB;create=true";
// create the data-source
gfsh.executeAndAssertThat(
"create data-source --name=jndi1 --username=myuser --password=mypass --pooled=false --url=\""
+ URL + "\"")
.statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1", "server-2");
createDataSource(URL);

// verify cluster config is updated
locator.invoke(() -> {
Expand Down Expand Up @@ -102,6 +98,15 @@ public void testCreateDataSource() throws Exception {
verifyThatNonExistentClassCausesGfshToError();
}

@SuppressWarnings("deprecation")
private void createDataSource(String URL) {
// create the data-source
gfsh.executeAndAssertThat(
"create data-source --name=jndi1 --username=myuser --password=mypass --pooled=false --url=\""
+ URL + "\"")
.statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1", "server-2");
}

@Test
public void testCreateDataSourceWithJarOptionDoesNotThrowDriverError() {
String URL = "jdbc:mysql://localhost/";
Expand Down Expand Up @@ -161,7 +166,7 @@ private void verifyThatNonExistentClassCausesGfshToError() {
}

private File loadTestResource(String fileName) {
String filePath = TestUtil.getResourcePath(this.getClass(), fileName);
String filePath = ResourceUtils.getResource(getClass(), fileName).getPath();
Assertions.assertThat(filePath).isNotNull();

return new File(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package org.apache.geode.connectors.jdbc.internal.cli;

import static junitparams.JUnitParamsRunner.$;
import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING;
import static org.apache.geode.connectors.jdbc.internal.cli.DescribeMappingCommand.DESCRIBE_MAPPING;
import static org.apache.geode.connectors.jdbc.internal.cli.DestroyMappingCommand.DESTROY_MAPPING;
Expand Down Expand Up @@ -111,7 +110,7 @@ public void before() throws Exception {
}

@After
public void after() throws Exception {
public void after() {
teardownDatabase();
}

Expand Down Expand Up @@ -168,10 +167,8 @@ private static RegionMapping getRegionMappingFromClusterConfig(String regionName
RegionConfig regionConfig = cacheConfig.getRegions().stream()
.filter(region -> region.getName().equals(convertRegionPathToName(regionName))).findFirst()
.orElse(null);
RegionMapping regionMapping =
(RegionMapping) regionConfig.getCustomRegionElements().stream()
.filter(element -> element instanceof RegionMapping).findFirst().orElse(null);
return regionMapping;
return (RegionMapping) regionConfig.getCustomRegionElements().stream()
.filter(element -> element instanceof RegionMapping).findFirst().orElse(null);
}

private static RegionMapping getRegionMappingFromService(String regionName) {
Expand Down Expand Up @@ -252,6 +249,7 @@ private static void validateRegionAlteredOnServer(String regionName, boolean syn
}
}

@SuppressWarnings("deprecation")
@Test
@Parameters(method = "parametersToTestPRDR")
public void createMappingTogetherForMultiServerGroupWithEmptyRegion(boolean isPR) {
Expand Down Expand Up @@ -320,6 +318,7 @@ public void createMappingTogetherForMultiServerGroupWithEmptyRegion(boolean isPR
gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
}

@SuppressWarnings("deprecation")
@Test
@Parameters(method = "parametersToTestPRDR")
public void createMappingSeparatelyForMultiServerGroupWithEmptyRegion(boolean isPR) {
Expand Down Expand Up @@ -416,6 +415,7 @@ public void createMappingSeparatelyForMultiServerGroupWithEmptyRegion(boolean is
gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
}

@SuppressWarnings("deprecation")
@Test
@Parameters(method = "parametersToTestPRDR")
public void createEmptyRegionAfterCreateMapping(boolean isPR) {
Expand Down Expand Up @@ -519,8 +519,9 @@ public void createEmptyRegionAfterCreateMapping(boolean isPR) {
gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
}

@SuppressWarnings("unused")
private Object[] parametersToTestPRDR() {
return $(true, false);
return new Object[] {true, false};
}

private static void assertValidMappingOnServer(RegionMapping mapping, String regionName,
Expand Down Expand Up @@ -580,14 +581,14 @@ String getName() {

@Override
public void toData(PdxWriter writer) {
writer.writeString("myid", this.id);
writer.writeString("name", this.name);
writer.writeString("myid", id);
writer.writeString("name", name);
}

@Override
public void fromData(PdxReader reader) {
this.id = reader.readString("myid");
this.name = reader.readString("name");
id = reader.readString("myid");
name = reader.readString("name");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.rules.GfshCommandRule;
import org.apache.geode.util.test.TestUtil;
import org.apache.geode.test.util.ResourceUtils;

public class DeregisterDriverCommandDUnitTest {

private static MemberVM locator, server1, server2;

@ClassRule
public static ClusterStartupRule cluster = new ClusterStartupRule();

Expand All @@ -41,9 +39,11 @@ public class DeregisterDriverCommandDUnitTest {

@BeforeClass
public static void before() throws Exception {
locator = cluster.startLocatorVM(0);
server1 = cluster.startServerVM(1, "group1", locator.getPort());
server2 = cluster.startServerVM(2, "group1", locator.getPort());
MemberVM locator = cluster.startLocatorVM(0);
@SuppressWarnings("unused")
MemberVM server1 = cluster.startServerVM(1, "group1", locator.getPort());
@SuppressWarnings("unused")
MemberVM server2 = cluster.startServerVM(2, "group1", locator.getPort());

gfsh.connectAndVerify(locator);
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public void testDeregisterDriverDoesNotThrowException() {
}

private File loadTestResource(String fileName) {
String filePath = TestUtil.getResourcePath(this.getClass(), fileName);
String filePath = ResourceUtils.getResource(this.getClass(), fileName).getPath();
Assertions.assertThat(filePath).isNotNull();

return new File(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

public class DescribeDataSourceCommandDUnitTest {

private MemberVM locator, server;
private MemberVM server;

@Rule
public ClusterStartupRule cluster = new ClusterStartupRule();
Expand All @@ -52,12 +52,13 @@ public class DescribeDataSourceCommandDUnitTest {

@Before
public void before() throws Exception {
locator = cluster.startLocatorVM(0);
MemberVM locator = cluster.startLocatorVM(0);
server = cluster.startServerVM(1, new Properties(), locator.getPort());

gfsh.connectAndVerify(locator);
}

@SuppressWarnings("deprecation")
@Test
public void describeDataSourceForSimpleDataSource() {
gfsh.executeAndAssertThat(
Expand Down Expand Up @@ -122,17 +123,18 @@ String getName() {

@Override
public void toData(PdxWriter writer) {
writer.writeString("myId", this.id);
writer.writeString("name", this.name);
writer.writeString("myId", id);
writer.writeString("name", name);
}

@Override
public void fromData(PdxReader reader) {
this.id = reader.readString("myId");
this.name = reader.readString("name");
id = reader.readString("myId");
name = reader.readString("name");
}
}

@SuppressWarnings("deprecation")
@Test
public void describeDataSourceUsedByRegionsListsTheRegionsInOutput() {
gfsh.executeAndAssertThat(
Expand Down Expand Up @@ -164,6 +166,7 @@ public void describeDataSourceUsedByRegionsListsTheRegionsInOutput() {
}
}

@SuppressWarnings("deprecation")
@Test
public void describeDataSourceForPooledDataSource() {
gfsh.executeAndAssertThat(
Expand Down
Loading

0 comments on commit 4fb85db

Please sign in to comment.