You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by zh...@apache.org on 2017/09/21 00:18:42 UTC
[geode] branch feature/GEODE-3569 updated: GEODE-3569: add junit
and dunit tests for fromData/toData add backward compatibility for
fromData/toData
This is an automated email from the ASF dual-hosted git repository.
zhouxj pushed a commit to branch feature/GEODE-3569
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-3569 by this push:
new 1d9b0ca GEODE-3569: add junit and dunit tests for fromData/toData add backward compatibility for fromData/toData
1d9b0ca is described below
commit 1d9b0ca051d2428bea970c31da460b67f6661741
Author: zhouxh <gz...@pivotal.io>
AuthorDate: Wed Sep 20 17:17:23 2017 -0700
GEODE-3569: add junit and dunit tests for fromData/toData
add backward compatibility for fromData/toData
---
.../internal/LuceneIndexCreationProfile.java | 10 ++++
.../cache/lucene/LuceneIndexCreationDUnitTest.java | 37 ++++++++++++++
.../LuceneIndexCreationProfileJUnitTest.java | 57 ++++++++++++++++------
3 files changed, 88 insertions(+), 16 deletions(-)
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfile.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfile.java
index 596709c..e666cb2 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfile.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfile.java
@@ -161,6 +161,11 @@ public class LuceneIndexCreationProfile implements CacheServiceProfile, DataSeri
@Override
public void toData(DataOutput out) throws IOException {
+ toDataPre_GEODE_1_3_0_0(out);
+ DataSerializer.writeString(this.serializerClass, out);
+ }
+
+ public void toDataPre_GEODE_1_3_0_0(DataOutput out) throws IOException {
DataSerializer.writeString(this.indexName, out);
DataSerializer.writeString(this.regionPath, out);
DataSerializer.writeStringArray(this.fieldNames, out);
@@ -170,6 +175,11 @@ public class LuceneIndexCreationProfile implements CacheServiceProfile, DataSeri
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
+ fromDataPre_GEODE_1_3_0_0(in);
+ this.serializerClass = DataSerializer.readString(in);
+ }
+
+ private void fromDataPre_GEODE_1_3_0_0(DataInput in) throws IOException, ClassNotFoundException {
this.indexName = DataSerializer.readString(in);
this.regionPath = DataSerializer.readString(in);
this.fieldNames = DataSerializer.readStringArray(in);
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
index b83ca44..29475a3 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
@@ -14,6 +14,7 @@
*/
package org.apache.geode.cache.lucene;
+import org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
import org.apache.geode.test.dunit.SerializableRunnableIF;
import org.apache.geode.test.junit.categories.DistributedTest;
@@ -324,6 +325,17 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
dataStore2.invoke(() -> initDataStore(createIndex2, regionType));
}
+ @Test
+ @Parameters("PARTITION")
+ public void verifyDifferentSerializerShouldFail(RegionTestableType regionType) {
+ SerializableRunnableIF createIndex1 = getIndexWithDefaultSerializer();
+ dataStore1.invoke(() -> initDataStore(createIndex1, regionType));
+
+ SerializableRunnableIF createIndex2 = getIndexWithDummySerializer();
+ dataStore2.invoke(() -> initDataStore(createIndex2, regionType,
+ CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_SERIALIZER));
+ }
+
protected String getXmlFileForTest(String testName) {
return TestUtil.getResourcePath(getClass(),
getClassSimpleName() + "." + testName + ".cache.xml");
@@ -462,4 +474,29 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
luceneService.createIndexFactory().setFields(analyzers).create(INDEX_NAME, REGION_NAME);
};
}
+
+ protected SerializableRunnableIF getIndexWithDummySerializer() {
+ return () -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ luceneService.createIndexFactory().setFields(new String[] {"field1", "field2"})
+ .setLuceneSerializer(new DummyLuceneSerializer()).create(INDEX_NAME, REGION_NAME);
+ };
+ }
+
+ protected SerializableRunnableIF getIndexWithDefaultSerializer() {
+ return () -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ luceneService.createIndexFactory().setFields(new String[] {"field1", "field2"})
+ .create(INDEX_NAME, REGION_NAME);
+ };
+ }
+
+ protected SerializableRunnableIF getHeterogeneousLuceneSerializerCreationProfile() {
+ return () -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ luceneService.createIndexFactory().setFields(new String[] {"field1", "field2"})
+ .setLuceneSerializer(new HeterogeneousLuceneSerializer(new String[] {"field1", "field2"}))
+ .create(INDEX_NAME, REGION_NAME);
+ };
+ }
}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfileJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfileJUnitTest.java
index 926d74b..c653c2f 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfileJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfileJUnitTest.java
@@ -15,11 +15,14 @@
package org.apache.geode.cache.lucene.internal;
import org.apache.geode.CopyHelper;
+import org.apache.geode.DataSerializer;
import org.apache.geode.cache.lucene.DummyLuceneSerializer;
-import org.apache.geode.cache.lucene.LuceneSerializer;
import org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
+import org.apache.geode.internal.HeapDataOutputStream;
+import org.apache.geode.internal.Version;
import org.apache.geode.test.junit.categories.UnitTest;
+
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.apache.lucene.analysis.Analyzer;
@@ -30,6 +33,9 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -57,10 +63,44 @@ public class LuceneIndexCreationProfileJUnitTest {
return $(new Object[] {getOneFieldLuceneIndexCreationProfile()},
new Object[] {getTwoFieldLuceneIndexCreationProfile()},
new Object[] {getTwoAnalyzersLuceneIndexCreationProfile()},
+ new Object[] {getDummySerializerCreationProfile()},
new Object[] {getNullField1AnalyzerLuceneIndexCreationProfile()});
}
@Test
+ @Parameters(method = "getProfileWithSerializer")
+ public void toDataFromDataShouldContainSerializer(LuceneIndexCreationProfile profile,
+ String expectedSerializerCLassName) throws IOException, ClassNotFoundException {
+ HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
+ DataSerializer.writeObject(profile, hdos);
+ byte[] outputArray = hdos.toByteArray();
+ ByteArrayInputStream bais = new ByteArrayInputStream(outputArray);
+ LuceneIndexCreationProfile profile2 = DataSerializer.readObject(new DataInputStream(bais));
+ assertEquals(expectedSerializerCLassName, profile2.getSerializerClass());
+ }
+
+ private Object[] getProfileWithSerializer() {
+ return $(new Object[] {getDefaultSerializerCreationProfile(), "HeterogeneousLuceneSerializer"},
+ new Object[] {getDummySerializerCreationProfile(), "DummyLuceneSerializer"}, new Object[] {
+ getHeterogeneousLuceneSerializerCreationProfile(), "HeterogeneousLuceneSerializer"});
+ }
+
+ private LuceneIndexCreationProfile getDefaultSerializerCreationProfile() {
+ return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME, new String[] {"field1"},
+ new StandardAnalyzer(), null, null);
+ }
+
+ private LuceneIndexCreationProfile getDummySerializerCreationProfile() {
+ return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME, new String[] {"field1"},
+ new StandardAnalyzer(), null, new DummyLuceneSerializer());
+ }
+
+ private LuceneIndexCreationProfile getHeterogeneousLuceneSerializerCreationProfile() {
+ return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME, new String[] {"field1"},
+ new StandardAnalyzer(), null, new HeterogeneousLuceneSerializer(new String[] {"field1"}));
+ }
+
+ @Test
@Parameters(method = "getCheckCompatibilityProfiles")
public void testCheckCompatibility(LuceneIndexCreationProfile myProfile,
LuceneIndexCreationProfile otherProfile, String expectedResult) {
@@ -92,21 +132,6 @@ public class LuceneIndexCreationProfileJUnitTest {
LuceneTestUtilities.CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_ANALYZERS_2});
}
- private LuceneIndexCreationProfile getDefaultSerializerCreationProfile() {
- return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME, new String[] {"field1"},
- new StandardAnalyzer(), null, null);
- }
-
- private LuceneIndexCreationProfile getDummySerializerCreationProfile() {
- return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME, new String[] {"field1"},
- new StandardAnalyzer(), null, new DummyLuceneSerializer());
- }
-
- private LuceneIndexCreationProfile getHeterogeneousLuceneSerializerCreationProfile() {
- return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME, new String[] {"field1"},
- new StandardAnalyzer(), null, new HeterogeneousLuceneSerializer(new String[] {"field1"}));
- }
-
private LuceneIndexCreationProfile getOneFieldLuceneIndexCreationProfile() {
return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME, new String[] {"field1"},
new StandardAnalyzer(), null, null);
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].