Skip to content

Commit

Permalink
IGNITE-6839 Delete binary meta before tests, PDS compatibility tests …
Browse files Browse the repository at this point in the history
…improved - Fixes apache#2990.

Signed-off-by: Alexey Goncharuk <alexey.goncharuk@gmail.com>
  • Loading branch information
dpavlov authored and agoncharuk committed Nov 10, 2017
1 parent a82ff06 commit 20ec6c9
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 65 deletions.
Expand Up @@ -17,6 +17,11 @@

package org.apache.ignite.compatibility.persistence;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheAtomicityMode;
Expand All @@ -28,14 +33,24 @@
import org.apache.ignite.configuration.PersistentStoreConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.processors.cache.GridCacheAbstractFullApiSelfTest;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;

/** */
/**
* Saves data using previous version of ignite and then load this data using actual version
*/
public class DummyPersistenceCompatibilityTest extends IgnitePersistenceCompatibilityAbstractTest {
/** */
private static final String TEST_CACHE_NAME = DummyPersistenceCompatibilityTest.class.getSimpleName();

/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
super.beforeTest();

deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "binary_meta", false));
}

/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
Expand All @@ -52,11 +67,41 @@ public class DummyPersistenceCompatibilityTest extends IgnitePersistenceCompatib
}

/**
* Tests opportunity to read data from previous Ignite DB version.
*
* @throws Exception If failed.
*/
public void testNodeStartByOldVersionPersistenceData_2_2() throws Exception {
doTestStartupWithOldVersion("2.2.0");
}

/**
* Tests opportunity to read data from previous Ignite DB version.
*
* @throws Exception If failed.
*/
public void testNodeStartByOldVersionPersistenceData_2_1() throws Exception {
doTestStartupWithOldVersion("2.1.0");
}

/**
* Tests opportunity to read data from previous Ignite DB version.
*
* @throws Exception If failed.
*/
public void testNodeStartByOldVersionPersistenceData_2_3() throws Exception {
doTestStartupWithOldVersion("2.3.0");
}

/**
* Tests opportunity to read data from previous Ignite DB version.
*
* @param ver 3-digits version of ignite
* @throws Exception If failed.
*/
public void testNodeStartByOldVersionPersistenceData() throws Exception {
private void doTestStartupWithOldVersion(String ver) throws Exception {
try {
startGrid(1, "2.2.0", new ConfigurationClosure(), new PostStartupClosure());
startGrid(1, ver, new ConfigurationClosure(), new PostStartupClosure());

stopAllGrids();

Expand All @@ -66,10 +111,23 @@ public void testNodeStartByOldVersionPersistenceData() throws Exception {

ignite.active(true);

IgniteCache<Integer, String> cache = ignite.getOrCreateCache(TEST_CACHE_NAME);
IgniteCache<Object, Object> cache = ignite.getOrCreateCache(TEST_CACHE_NAME);

for (int i = 0; i < 10; i++)
assertEquals("data" + i, cache.get(i));

assertEquals(cache.get("1"), "2");
assertEquals(cache.get(12), 2);
assertEquals(cache.get(13L), 2L);
assertEquals(cache.get(TestEnum.A), "Enum_As_Key");
assertEquals(cache.get("Enum_As_Value"), TestEnum.B);
assertEquals(cache.get(TestEnum.C), TestEnum.C);
assertEquals(cache.get("Serializable"), new TestSerializable(42));
assertEquals(cache.get(new TestSerializable(42)), "Serializable_As_Key");
assertEquals(cache.get("Externalizable"), new TestExternalizable(42));
assertEquals(cache.get(new TestExternalizable(42)), "Externalizable_As_Key");
assertEquals(cache.get("testStringContainer"),
new TestStringContainerToBePrinted("testStringContainer"));
}
finally {
stopAllGrids();
Expand All @@ -82,16 +140,28 @@ private static class PostStartupClosure implements IgniteInClosure<Ignite> {
@Override public void apply(Ignite ignite) {
ignite.active(true);

CacheConfiguration<Integer, String> cacheCfg = new CacheConfiguration<>();
CacheConfiguration<Object, Object> cacheCfg = new CacheConfiguration<>();
cacheCfg.setName(TEST_CACHE_NAME);
cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cacheCfg.setBackups(1);
cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

IgniteCache<Integer, String> cache = ignite.createCache(cacheCfg);
IgniteCache<Object, Object> cache = ignite.createCache(cacheCfg);

for (int i = 0; i < 10; i++)
cache.put(i, "data" + i);

cache.put("1", "2");
cache.put(12, 2);
cache.put(13L, 2L);
cache.put(TestEnum.A, "Enum_As_Key");
cache.put("Enum_As_Value", TestEnum.B);
cache.put(TestEnum.C, TestEnum.C);
cache.put("Serializable", new TestSerializable(42));
cache.put(new TestSerializable(42), "Serializable_As_Key");
cache.put("Externalizable", new TestExternalizable(42));
cache.put(new TestExternalizable(42), "Externalizable_As_Key");
cache.put("testStringContainer", new TestStringContainerToBePrinted("testStringContainer"));
}
}

Expand All @@ -111,4 +181,147 @@ private static class ConfigurationClosure implements IgniteInClosure<IgniteConfi
cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration());
}
}

/** Enum for cover binaryObject enum save/load. */
public enum TestEnum {
/** */A, /** */B, /** */C
}

/** Special class to test WAL reader resistance to Serializable interface. */
static class TestSerializable implements Serializable {
/** */
private static final long serialVersionUID = 0L;

/** I value. */
private int iVal;

/**
* Creates test object
*
* @param iVal I value.
*/
TestSerializable(int iVal) {
this.iVal = iVal;
}

/** {@inheritDoc} */
@Override public String toString() {
return "TestSerializable{" +
"iVal=" + iVal +
'}';
}

/** {@inheritDoc} */
@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

TestSerializable that = (TestSerializable)o;

return iVal == that.iVal;
}

/** {@inheritDoc} */
@Override public int hashCode() {
return iVal;
}
}

/** Special class to test WAL reader resistance to Serializable interface. */
static class TestExternalizable implements Externalizable {
/** */
private static final long serialVersionUID = 0L;

/** I value. */
private int iVal;

/** Noop ctor for unmarshalling */
public TestExternalizable() {

}

/**
* Creates test object with provided value.
*
* @param iVal I value.
*/
public TestExternalizable(int iVal) {
this.iVal = iVal;
}

/** {@inheritDoc} */
@Override public String toString() {
return "TestExternalizable{" +
"iVal=" + iVal +
'}';
}

/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(iVal);
}

/** {@inheritDoc} */
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
iVal = in.readInt();
}

/** {@inheritDoc} */
@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

TestExternalizable that = ( TestExternalizable)o;

return iVal == that.iVal;
}

/** {@inheritDoc} */
@Override public int hashCode() {
return iVal;
}
}

/** Container class to test toString of data records. */
static class TestStringContainerToBePrinted {
/** */
String data;

/**
* Creates container.
*
* @param data value to be searched in to String.
*/
public TestStringContainerToBePrinted(String data) {
this.data = data;
}

/** {@inheritDoc} */
@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

TestStringContainerToBePrinted printed = (TestStringContainerToBePrinted)o;

return data != null ? data.equals(printed.data) : printed.data == null;
}

/** {@inheritDoc} */
@Override public int hashCode() {
return data != null ? data.hashCode() : 0;
}

/** {@inheritDoc} */
@Override public String toString() {
return "TestStringContainerToBePrinted{" +
"data='" + data + '\'' +
'}';
}
}
}
Expand Up @@ -23,6 +23,7 @@
import java.util.Set;
import java.util.TreeSet;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.MemoryConfiguration;
Expand All @@ -46,17 +47,27 @@ public class FoldersReuseCompatibilityTest extends IgnitePersistenceCompatibilit
private static final String CACHE_NAME = "dummy";

/** Key to store in previous version of ignite */
private static final String KEY = "ObjectFromPast";
private static final String KEY = "StringFromPrevVersion";

/** Value to store in previous version of ignite */
private static final String VAL = "ValueFromPast";
private static final String VAL = "ValueFromPrevVersion";

/** Key to store in previous version of ignite */
private static final String KEY_OBJ = "ObjectFromPrevVersion";

/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
// No-op. super.afterTest();
stopAllGrids();
}

/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
super.beforeTest();

deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "binary_meta", false));
}

/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
final IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
Expand All @@ -66,6 +77,16 @@ public class FoldersReuseCompatibilityTest extends IgnitePersistenceCompatibilit
return cfg;
}

/**
* Test startup of current ignite version using DB storage folder from previous version of Ignite. Expected to start
* successfully with existing DB
*
* @throws Exception if failed.
*/
public void ignored_testFoldersReuseCompatibility_2_3() throws Exception {
runFoldersReuse("2.3.0");
}

/**
* Test startup of current ignite version using DB storage folder from previous version of Ignite. Expected to start
* successfully with existing DB
Expand Down Expand Up @@ -94,9 +115,8 @@ public void testFoldersReuseCompatibility_2_1() throws Exception {
* @throws Exception if failed.
*/
private void runFoldersReuse(String ver) throws Exception {
final IgniteEx grid = startGrid(1, ver, new ConfigurationClosure(), new PostStartupClosure());
final IgniteEx oldVer = startGrid(1, ver, new ConfigurationClosure(), new PostStartupClosure());

grid.close();
stopAllGrids();

IgniteEx ignite = startGrid(0);
Expand All @@ -109,6 +129,9 @@ private void runFoldersReuse(String ver) throws Exception {

assertEquals(VAL, ignite.cache(CACHE_NAME).get(KEY));

final DummyPersistenceCompatibilityTest.TestStringContainerToBePrinted actual = (DummyPersistenceCompatibilityTest.TestStringContainerToBePrinted)ignite.cache(CACHE_NAME).get(KEY_OBJ);
assertEquals(VAL, actual.data);

assertNodeIndexesInFolder();// should not create any new style directories

stopAllGrids();
Expand All @@ -119,7 +142,22 @@ private static class PostStartupClosure implements IgniteInClosure<Ignite> {
/** {@inheritDoc} */
@Override public void apply(Ignite ignite) {
ignite.active(true);
ignite.getOrCreateCache(CACHE_NAME).put(KEY, VAL);

final IgniteCache<Object, Object> cache = ignite.getOrCreateCache(CACHE_NAME);
cache.put(KEY, VAL);
cache.put("1", "2");
cache.put(1, 2);
cache.put(1L, 2L);
cache.put(DummyPersistenceCompatibilityTest.TestEnum.A, "Enum_As_Key");
cache.put("Enum_As_Value", DummyPersistenceCompatibilityTest.TestEnum.B);
cache.put(DummyPersistenceCompatibilityTest.TestEnum.C, DummyPersistenceCompatibilityTest.TestEnum.C);

cache.put("Serializable", new DummyPersistenceCompatibilityTest.TestSerializable(42));
cache.put(new DummyPersistenceCompatibilityTest.TestSerializable(42), "Serializable_As_Key");
cache.put("Externalizable", new DummyPersistenceCompatibilityTest.TestExternalizable(42));
cache.put(new DummyPersistenceCompatibilityTest.TestExternalizable(42), "Externalizable_As_Key");
cache.put(KEY_OBJ, new DummyPersistenceCompatibilityTest.TestStringContainerToBePrinted(VAL));

}
}

Expand Down
Expand Up @@ -94,7 +94,7 @@
* Dummy grid kernal context
*/
public class StandaloneGridKernalContext implements GridKernalContext {
/** Binary metadata file store folderю */
/** Binary metadata file store folder. */
public static final String BINARY_META_FOLDER = "binary_meta";

/** Config for fake Ignite instance. */
Expand Down

0 comments on commit 20ec6c9

Please sign in to comment.