Repository: geode Updated Branches: refs/heads/feature/GEODE-2632-6-1 915a0c53c -> d79314297
Fix test failures Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/d7931429 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/d7931429 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/d7931429 Branch: refs/heads/feature/GEODE-2632-6-1 Commit: d79314297831990f788bb1b39bf0f7d489c6e7ea Parents: 915a0c5 Author: Kirk Lund <[email protected]> Authored: Mon Apr 24 22:43:44 2017 -0700 Committer: Kirk Lund <[email protected]> Committed: Mon Apr 24 22:43:44 2017 -0700 ---------------------------------------------------------------------- .../geode/internal/cache/GemFireCacheImpl.java | 16 +- .../NewDeclarativeIndexCreationJUnitTest.java | 184 +++++++++---------- 2 files changed, 101 insertions(+), 99 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/d7931429/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java index 010ec43..d18b683 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java @@ -632,7 +632,7 @@ public class GemFireCacheImpl * {@link org.apache.geode.cache.CacheExistsException}) */ @Override - public final String toString() { + public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("GemFireCache["); sb.append("id = ").append(System.identityHashCode(this)); @@ -1389,8 +1389,18 @@ public class GemFireCacheImpl .toLocalizedString(url.toString(), ex)); } catch (CacheXmlException ex) { - throw new CacheXmlException(LocalizedStrings.GemFireCache_WHILE_READING_CACHE_XML_0_1 - .toLocalizedString(url, ex.getMessage()), ex); + CacheXmlException newEx = + new CacheXmlException(LocalizedStrings.GemFireCache_WHILE_READING_CACHE_XML_0_1 + .toLocalizedString(url, ex.getMessage())); + /* + * TODO: why use setStackTrace and initCause? removal breaks several tests: + * OplogRVVJUnitTest, NewDeclarativeIndexCreationJUnitTest + * CacheXml70DUnitTest, CacheXml80DUnitTest, CacheXml81DUnitTest, CacheXmlGeode10DUnitTest + * RegionManagementDUnitTest + */ + newEx.setStackTrace(ex.getStackTrace()); + newEx.initCause(ex.getCause()); + throw newEx; } finally { if (stream != null) { http://git-wip-us.apache.org/repos/asf/geode/blob/d7931429/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/NewDeclarativeIndexCreationJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/NewDeclarativeIndexCreationJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/NewDeclarativeIndexCreationJUnitTest.java index 8a0f31c..780a7a8 100644 --- a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/NewDeclarativeIndexCreationJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/NewDeclarativeIndexCreationJUnitTest.java @@ -12,161 +12,153 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ -/** - * - */ package org.apache.geode.cache.query.internal.index; -import org.apache.geode.cache.*; +import static org.apache.geode.distributed.ConfigurationProperties.CACHE_XML_FILE; +import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.apache.commons.io.FileUtils; +import org.apache.geode.InternalGemFireException; +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.cache.CacheXmlException; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionAttributes; import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.test.junit.categories.IntegrationTest; -import org.apache.geode.util.test.TestUtil; import org.junit.After; -import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Collection; +import java.io.File; import java.util.Properties; -import static org.apache.geode.distributed.ConfigurationProperties.*; - /** - * * @since GemFire 6.6.1 */ @Category(IntegrationTest.class) public class NewDeclarativeIndexCreationJUnitTest { - private Cache cache = null; + private static final String CACHE_XML_FILE_NAME = "cachequeryindex.xml"; + + private Cache cache; + private File cacheXmlFile; + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); @Before public void setUp() throws Exception { - // Read the Cache.xml placed in test.lib folder + this.cacheXmlFile = this.temporaryFolder.newFile(CACHE_XML_FILE_NAME); + FileUtils.copyURLToFile(getClass().getResource(CACHE_XML_FILE_NAME), this.cacheXmlFile); + assertThat(this.cacheXmlFile).exists(); // precondition + Properties props = new Properties(); - props.setProperty(CACHE_XML_FILE, TestUtil.getResourcePath(getClass(), "cachequeryindex.xml")); + props.setProperty(CACHE_XML_FILE, this.cacheXmlFile.getAbsolutePath()); props.setProperty(MCAST_PORT, "0"); DistributedSystem ds = DistributedSystem.connect(props); - cache = CacheFactory.create(ds); + this.cache = CacheFactory.create(ds); } @After public void tearDown() throws Exception { - if (!cache.isClosed()) - cache.close(); + if (this.cache != null) { + this.cache.close(); + } } @Test public void testAsynchronousIndexCreatedOnRoot_PortfoliosRegion() { - Region root = cache.getRegion("/root/portfolios"); + Region root = this.cache.getRegion("/root/portfolios"); IndexManager im = IndexUtils.getIndexManager(root, true); - Collection coll = im.getIndexes(); - if (coll.size() > 0) { - Assert.assertTrue(true); - // System.out.println("List of indexes= " + im.toString()); - RegionAttributes ra = root.getAttributes(); - Assert.assertTrue(!ra.getIndexMaintenanceSynchronous()); - } else - Assert.fail( - "NewDeclarativeIndexCreationJUnitTest::testAsynchronousIndexCreatedOnRoot_PortfoliosRegion:No index found in the root region"); + assertThat(im.getIndexes()).isNotEmpty(); + + RegionAttributes ra = root.getAttributes(); + assertThat(ra.getIndexMaintenanceSynchronous()).isFalse(); } @Test public void testSynchronousIndexCreatedOnRoot_StringRegion() { - Region root = cache.getRegion("/root/string"); - IndexManager im = IndexUtils.getIndexManager(root, true);; - Collection coll = im.getIndexes(); - if (coll.size() > 0) { - Assert.assertTrue(true); - // System.out.println("List of indexes= " + im.toString()); - RegionAttributes ra = root.getAttributes(); - Assert.assertTrue(ra.getIndexMaintenanceSynchronous()); - } else - Assert.fail( - "NewDeclarativeIndexCreationJUnitTest::testSynchronousIndexCreatedOnRoot_StringRegion Region:No index found in the root region"); - root = cache.getRegion("/root/string1"); + Region root = this.cache.getRegion("/root/string"); + IndexManager im = IndexUtils.getIndexManager(root, true); + assertThat(im.getIndexes()).isNotEmpty(); + + RegionAttributes ra = root.getAttributes(); + assertThat(ra.getIndexMaintenanceSynchronous()).isTrue(); + + root = this.cache.getRegion("/root/string1"); im = IndexUtils.getIndexManager(root, true); - if (!im.isIndexMaintenanceTypeSynchronous()) - Assert.fail( - "NewDeclarativeIndexCreationJUnitTest::testSynchronousIndexCreatedOnRoot_StringRegion: The index update type not synchronous if no index-update-type attribuet specified in cache.cml"); + assertThat(im.isIndexMaintenanceTypeSynchronous()).isTrue(); } @Test public void testSynchronousIndexCreatedOnRootRegion() { - Region root = cache.getRegion("/root"); + Region root = this.cache.getRegion("/root"); IndexManager im = IndexUtils.getIndexManager(root, true); - Collection coll = im.getIndexes(); - if (coll.size() > 0) { - Assert.assertTrue(true); - // System.out.println("List of indexes= " + im.toString()); - RegionAttributes ra = root.getAttributes(); - Assert.assertTrue(ra.getIndexMaintenanceSynchronous()); - } else - Assert.fail( - "NewDeclarativeIndexCreationJUnitTest::testAsynchronousIndexCreatedOnRoot_PortfoliosRegion:No index found in the root region"); + assertThat(im.getIndexes()).isNotEmpty(); + + RegionAttributes ra = root.getAttributes(); + assertThat(ra.getIndexMaintenanceSynchronous()).isTrue(); } - // Index creation tests for new DTD changes for Index tag for 6.6.1 with no function/primary-key - // tag + /** + * Index creation tests for new DTD changes for Index tag for 6.6.1 with no function/primary-key + * tag + */ @Test public void testAsynchronousIndexCreatedOnPortfoliosRegionWithNewDTD() { - Region root = cache.getRegion("/root/portfolios2"); + Region root = this.cache.getRegion("/root/portfolios2"); IndexManager im = IndexUtils.getIndexManager(root, true); - Collection coll = im.getIndexes(); - if (coll.size() > 0) { - Assert.assertTrue(true); - // System.out.println("List of indexes= " + im.toString()); - RegionAttributes ra = root.getAttributes(); - Assert.assertTrue(!ra.getIndexMaintenanceSynchronous()); - } else - Assert.fail( - "NewDeclarativeIndexCreationJUnitTest::testAsynchronousIndexCreatedOnRoot_PortfoliosRegion:No index found in the root region"); + assertThat(im.getIndexes()).isNotEmpty(); + + RegionAttributes ra = root.getAttributes(); + assertThat(ra.getIndexMaintenanceSynchronous()).isFalse(); } @Test public void testSynchronousIndexCreatedOnStringRegionWithNewDTD() { - Region root = cache.getRegion("/root/string2"); + Region root = this.cache.getRegion("/root/string2"); IndexManager im = IndexUtils.getIndexManager(root, true);; - Collection coll = im.getIndexes(); - if (coll.size() > 0) { - Assert.assertTrue(true); - // System.out.println("List of indexes= " + im.toString()); - RegionAttributes ra = root.getAttributes(); - Assert.assertTrue(ra.getIndexMaintenanceSynchronous()); - } else - Assert.fail( - "NewDeclarativeIndexCreationJUnitTest::testSynchronousIndexCreatedOnRoot_StringRegion Region:No index found in the root region"); - root = cache.getRegion("/root/string1"); + assertThat(im.getIndexes()).isNotEmpty(); + + RegionAttributes ra = root.getAttributes(); + assertThat(ra.getIndexMaintenanceSynchronous()).isTrue(); + + root = this.cache.getRegion("/root/string1"); im = IndexUtils.getIndexManager(root, true); - if (!im.isIndexMaintenanceTypeSynchronous()) - Assert.fail( - "DeclarativeIndexCreationTest::testSynchronousIndexCreatedOnRoot_StringRegion: The index update type not synchronous if no index-update-type attribuet specified in cache.cml"); + assertThat(im.isIndexMaintenanceTypeSynchronous()).isTrue(); } + /** + * TODO: move this to a different test class because it requires different setup + */ @Test - public void testIndexCreationExceptionOnRegionWithNewDTD() - throws IOException, URISyntaxException { - if (cache != null && !cache.isClosed()) - cache.close(); + public void testIndexCreationExceptionOnRegionWithNewDTD() throws Exception { + if (this.cache != null && !this.cache.isClosed()) { + this.cache.close(); + } + + this.cacheXmlFile = this.temporaryFolder.newFile("cachequeryindexwitherror.xml"); + FileUtils.copyURLToFile(getClass().getResource("cachequeryindexwitherror.xml"), this.cacheXmlFile); + assertThat(this.cacheXmlFile).exists(); // precondition + Properties props = new Properties(); - props.setProperty(CACHE_XML_FILE, - TestUtil.getResourcePath(getClass(), "cachequeryindexwitherror.xml")); + props.setProperty(CACHE_XML_FILE, this.cacheXmlFile.getAbsolutePath()); props.setProperty(MCAST_PORT, "0"); + DistributedSystem ds = DistributedSystem.connect(props); - try { - Cache cache = CacheFactory.create(ds); - } catch (CacheXmlException e) { - if (!e.getCause().getMessage() - .contains("CacheXmlParser::endIndex:Index creation attribute not correctly specified.")) { - e.printStackTrace(); - Assert.fail( - "NewDeclarativeIndexCreationJUnitTest::setup: Index creation should have thrown exception for index on /root/portfolios3 region."); - } - return; - } + + // TODO: refactoring GemFireCacheImpl.initializeDeclarativeCache requires change here + assertThatThrownBy(() -> CacheFactory.create(ds)) + .isExactlyInstanceOf(CacheXmlException.class) + .hasCauseInstanceOf(InternalGemFireException.class); + + // hasCauseMessageContaining("CacheXmlParser::endIndex:Index creation attribute not correctly specified."); } }
