Skip to content
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

GEODE-6527: when user explicitly specify PartitionedAttributes, such as #3424

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,28 @@
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.apache.geode.cache.Region;
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService;
import org.apache.geode.connectors.jdbc.internal.configuration.FieldMapping;
import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping;
import org.apache.geode.connectors.util.internal.MappingCommandUtils;
import org.apache.geode.pdx.FieldType;
import org.apache.geode.pdx.PdxInstance;
import org.apache.geode.pdx.ReflectionBasedAutoSerializer;
import org.apache.geode.pdx.internal.AutoSerializableManager;
Expand Down Expand Up @@ -323,8 +330,31 @@ public void serverStartupSucceedsForPartitionedRegionAfterMappingIsCreated()
createTable();
createPartitionRegionUsingGfsh();
createJdbcDataSource();
createMapping(REGION_NAME, DATA_SOURCE_NAME, true);
startupRule.startServerVM(3, x -> x.withConnectionToLocator(locator.getPort()));
createMapping(REGION_NAME, DATA_SOURCE_NAME, false);
MemberVM server5 =
startupRule.startServerVM(3, x -> x.withConnectionToLocator(locator.getPort()));
server5.invoke(() -> {
RegionMapping mapping =
ClusterStartupRule.getCache().getService(JdbcConnectorService.class)
.getMappingForRegion(REGION_NAME);
assertThat(mapping.getDataSourceName()).isEqualTo(DATA_SOURCE_NAME);
assertThat(mapping.getPdxName()).isEqualTo(Employee.class.getName());
assertThat(mapping.getTableName()).isEqualTo(TABLE_NAME);
List<FieldMapping> fieldMappings = mapping.getFieldMappings();
assertThat(fieldMappings.size()).isEqualTo(3);
assertThat(fieldMappings.get(0)).isEqualTo(
new FieldMapping("name", FieldType.STRING.name(), "name", JDBCType.VARCHAR.name(),
true));
assertThat(fieldMappings.get(1)).isEqualTo(
new FieldMapping("id", FieldType.STRING.name(), "id", JDBCType.VARCHAR.name(), false));
assertThat(fieldMappings.get(2)).isEqualTo(
new FieldMapping("age", FieldType.INT.name(), "age", JDBCType.INTEGER.name(), false));

String queueName = MappingCommandUtils.createAsyncEventQueueName(REGION_NAME);
AsyncEventQueue queue = ClusterStartupRule.getCache().getAsyncEventQueue(queueName);
assertThat(queue).isNotNull();
assertThat(queue.getAsyncEventListener()).isInstanceOf(JdbcAsyncWriter.class);
});
}

@Test
Expand Down Expand Up @@ -751,7 +781,8 @@ private void createRegionUsingGfsh() {

private void createPartitionRegionUsingGfsh() {
StringBuffer createRegionCmd = new StringBuffer();
createRegionCmd.append("create region --name=" + REGION_NAME + " --type=PARTITION");
createRegionCmd
.append("create region --name=" + REGION_NAME + " --type=PARTITION --redundant-copies=1");
gfsh.executeAndAssertThat(createRegionCmd.toString()).statusIsSuccess();
}

Expand All @@ -768,6 +799,7 @@ private void createMapping(String regionName, String connectionName, String pdxC
boolean synchronous, String ids) {
final String commandStr = "create jdbc-mapping --region=" + regionName
+ " --data-source=" + connectionName
+ " --table=" + TABLE_NAME
+ " --synchronous=" + synchronous
+ " --pdx-name=" + pdxClassName
+ ((ids != null) ? (" --id=" + ids) : "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public static CacheConfig.AsyncEventQueue findAsyncEventQueue(CacheConfig cacheC
public static boolean isAccessor(RegionAttributesType attributesType) {
if (attributesType.getDataPolicy() == RegionAttributesDataPolicy.EMPTY
|| (attributesType.getPartitionAttributes() != null
&& attributesType.getPartitionAttributes().getLocalMaxMemory() != null
&& attributesType.getPartitionAttributes().getLocalMaxMemory().equals("0"))) {
return true;
} else {
Expand Down