Skip to content

Commit

Permalink
IGNITE-15083 Remove "instanceof BinaryMarshaller" from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov committed Dec 26, 2024
1 parent 5590b01 commit 439219d
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.ConnectorConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.testframework.GridTestUtils;
Expand Down Expand Up @@ -820,8 +819,7 @@ public void testUrl() throws Exception {
@Test
public void testObject() throws Exception {
final Ignite ignite = ignite(0);
final boolean binaryMarshaller = ignite.configuration().getMarshaller() instanceof BinaryMarshaller;
final IgniteBinary binary = binaryMarshaller ? ignite.binary() : null;
final IgniteBinary binary = ignite.binary();
ResultSet rs = stmt.executeQuery(SQL);

TestObjectField f1 = new TestObjectField(100, "AAAA");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.apache.ignite.cache.store.jdbc.model.Person;
import org.apache.ignite.cache.store.jdbc.model.PersonComplexKey;
import org.apache.ignite.cache.store.jdbc.model.PersonKey;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.processors.cache.CacheEntryImpl;
import org.apache.ignite.internal.util.typedef.CI2;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand All @@ -74,9 +73,6 @@ public class CacheJdbcPojoStoreTest extends GridAbstractCacheStoreSelfTest<Cache
/** Ignite. */
private Ignite ig;

/** Binary enable. */
private boolean binaryEnable;

/**
* @throws Exception If failed.
*/
Expand Down Expand Up @@ -291,8 +287,6 @@ public CacheJdbcPojoStoreTest() throws Exception {
Ignite ig = U.field(store, "ignite");

this.ig = ig;

binaryEnable = ig.configuration().getMarshaller() instanceof BinaryMarshaller;
}

/**
Expand Down Expand Up @@ -385,49 +379,28 @@ public void testLoadCache() throws Exception {

IgniteBiInClosure<Object, Object> c = new CI2<Object, Object>() {
@Override public void apply(Object k, Object v) {
if (binaryEnable) {
if (k instanceof BinaryObject && v instanceof BinaryObject) {
BinaryObject key = (BinaryObject)k;
BinaryObject val = (BinaryObject)v;

String keyType = key.type().typeName();
String valType = val.type().typeName();

if (OrganizationKey.class.getName().equals(keyType)
&& Organization.class.getName().equals(valType))
orgKeys.add(key);

if (PersonKey.class.getName().equals(keyType)
&& Person.class.getName().equals(valType))
prnKeys.add(key);

if (PersonComplexKey.class.getName().equals(keyType)
&& Person.class.getName().equals(valType))
prnComplexKeys.add(key);

if (BinaryTestKey.class.getName().equals(keyType)
&& BinaryTest.class.getName().equals(valType))
binaryTestVals.add(val.field("bytes"));
}
}
else {
if (k instanceof OrganizationKey && v instanceof Organization)
orgKeys.add(k);
else if (k instanceof PersonKey && v instanceof Person)
prnKeys.add(k);
else if (k instanceof BinaryTestKey && v instanceof BinaryTest)
binaryTestVals.add(((BinaryTest)v).getBytes());
else if (k instanceof PersonComplexKey && v instanceof Person) {
PersonComplexKey key = (PersonComplexKey)k;

Person val = (Person)v;

assertTrue("Key ID should be the same as value ID", key.getId() == val.getId());
assertTrue("Key orgID should be the same as value orgID", key.getOrgId() == val.getOrgId());
assertEquals("name" + key.getId(), val.getName());

prnComplexKeys.add(k);
}
if (k instanceof BinaryObject && v instanceof BinaryObject) {
BinaryObject key = (BinaryObject)k;
BinaryObject val = (BinaryObject)v;

String keyType = key.type().typeName();
String valType = val.type().typeName();

if (OrganizationKey.class.getName().equals(keyType)
&& Organization.class.getName().equals(valType))
orgKeys.add(key);

if (PersonKey.class.getName().equals(keyType)
&& Person.class.getName().equals(valType))
prnKeys.add(key);

if (PersonComplexKey.class.getName().equals(keyType)
&& Person.class.getName().equals(valType))
prnComplexKeys.add(key);

if (BinaryTestKey.class.getName().equals(keyType)
&& BinaryTest.class.getName().equals(valType))
binaryTestVals.add(val.field("bytes"));
}
}
};
Expand Down Expand Up @@ -505,24 +478,16 @@ public void testParallelLoad() throws Exception {

IgniteBiInClosure<Object, Object> c = new CI2<Object, Object>() {
@Override public void apply(Object k, Object v) {
if (binaryEnable) {
if (k instanceof BinaryObject && v instanceof BinaryObject) {
BinaryObject key = (BinaryObject)k;
BinaryObject val = (BinaryObject)v;

String keyType = key.type().typeName();
String valType = val.type().typeName();

if (PersonComplexKey.class.getName().equals(keyType)
&& Person.class.getName().equals(valType))
prnComplexKeys.add(key);
}
}
else {
if (k instanceof PersonComplexKey && v instanceof Person)
prnComplexKeys.add(k);
else
fail("Unexpected entry [key=" + k + ", value=" + v + "]");
if (k instanceof BinaryObject && v instanceof BinaryObject) {
BinaryObject key = (BinaryObject)k;
BinaryObject val = (BinaryObject)v;

String keyType = key.type().typeName();
String valType = val.type().typeName();

if (PersonComplexKey.class.getName().equals(keyType)
&& Person.class.getName().equals(valType))
prnComplexKeys.add(key);
}
}
};
Expand Down Expand Up @@ -648,24 +613,13 @@ public void testLoadCacheLobFields() throws Exception {

IgniteBiInClosure<Object, Object> c = new CI2<Object, Object>() {
@Override public void apply(Object k, Object v) {
if (binaryEnable) {
assertTrue(k instanceof BinaryObject);
assertTrue(v instanceof BinaryObject);

BinaryObject val = (BinaryObject)v;
assertTrue(k instanceof BinaryObject);
assertTrue(v instanceof BinaryObject);

assertTrue(Arrays.equals(picture, val.field("picture")));
assertEquals(longDescription, val.field("description"));
}
else {
assertTrue(k instanceof LogoKey);
assertTrue(v instanceof Logo);

Logo val = (Logo)v;
BinaryObject val = (BinaryObject)v;

assertTrue(Arrays.equals(picture, val.getPicture()));
assertEquals(longDescription, val.getDescription());
}
assertTrue(Arrays.equals(picture, val.field("picture")));
assertEquals(longDescription, val.field("description"));
}
};

Expand Down Expand Up @@ -720,23 +674,19 @@ public void testLobWrite() throws Exception {
* @param obj Object.
*/
private Object wrap(Object obj) throws IllegalAccessException {
if (binaryEnable) {
Class<?> cls = obj.getClass();
Class<?> cls = obj.getClass();

BinaryObjectBuilder builder = ig.binary().builder(cls.getName());
BinaryObjectBuilder builder = ig.binary().builder(cls.getName());

for (Field f : cls.getDeclaredFields()) {
if (f.getName().contains("serialVersionUID"))
continue;
for (Field f : cls.getDeclaredFields()) {
if (f.getName().contains("serialVersionUID"))
continue;

f.setAccessible(true);

builder.setField(f.getName(), f.get(obj));
}
f.setAccessible(true);

return builder.build();
builder.setField(f.getName(), f.get(obj));
}

return obj;
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.ignite.cache.CacheEntryProcessor;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
Expand Down Expand Up @@ -102,8 +101,7 @@ private void doTestMutableEntry(boolean p2pEnabled) throws Exception {

// One deserialization due to copyOnRead == true.
// Additional deserialization in case p2p enabled and not BinaryMarshaller due to storeValue == true on update entry.
doTest(true, true, NEW_VAL, p2pEnabled &&
!(grid.configuration().getMarshaller() instanceof BinaryMarshaller) ? 2 : 1);
doTest(true, true, NEW_VAL, 1);

// No deserialization.
doTest(false, false, NEW_VAL, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.internal.binary.BinaryEnumObjectImpl;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;

Expand Down Expand Up @@ -187,15 +185,11 @@ private void enumOperations(IgniteCache<Object, Object> cache, int key) {
* @param expVal Expected value.
*/
private static void assertBinaryEnum(IgniteCache<Object, Object> cache, int key, TestEnum expVal) {
Marshaller marsh = ((IgniteCacheProxy)cache).context().marshaller();
BinaryObject enumObj = (BinaryObject)cache.withKeepBinary().get(key);

if (marsh instanceof BinaryMarshaller) {
BinaryObject enumObj = (BinaryObject)cache.withKeepBinary().get(key);

assertEquals(expVal.ordinal(), enumObj.enumOrdinal());
assertTrue(enumObj.type().isEnum());
assertTrue(enumObj instanceof BinaryEnumObjectImpl);
}
assertEquals(expVal.ordinal(), enumObj.enumOrdinal());
assertTrue(enumObj.type().isEnum());
assertTrue(enumObj instanceof BinaryEnumObjectImpl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.DeploymentMode;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;

Expand All @@ -40,14 +38,10 @@ public class CacheStartupInDeploymentModesTest extends GridCommonAbstractTest {
/** */
private DeploymentMode deploymentMode;

/** */
private Marshaller marshaller;

/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

cfg.setMarshaller(marshaller);
cfg.setDeploymentMode(deploymentMode);

CacheConfiguration cacheCfg1 = new CacheConfiguration(DEFAULT_CACHE_NAME);
Expand Down Expand Up @@ -76,7 +70,6 @@ public class CacheStartupInDeploymentModesTest extends GridCommonAbstractTest {
@Test
public void testStartedInIsolatedMode() throws Exception {
deploymentMode = DeploymentMode.ISOLATED;
marshaller = new BinaryMarshaller();

doCheckStarted(deploymentMode);
}
Expand All @@ -87,7 +80,6 @@ public void testStartedInIsolatedMode() throws Exception {
@Test
public void testStartedInPrivateMode() throws Exception {
deploymentMode = DeploymentMode.PRIVATE;
marshaller = new BinaryMarshaller();

doCheckStarted(deploymentMode);
}
Expand All @@ -103,8 +95,6 @@ private void doCheckStarted(DeploymentMode mode) throws Exception {

assertEquals(mode, ignite(0).configuration().getDeploymentMode());

assert ignite(0).configuration().getMarshaller() instanceof BinaryMarshaller;

IgniteCache rCache = ignite(0).cache(REPLICATED_CACHE);

checkPutCache(rCache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.plugin.AbstractTestPluginProvider;
import org.apache.ignite.plugin.ExtensionRegistry;
Expand Down Expand Up @@ -108,21 +107,7 @@ public void testNoDeploymentInfo() throws Exception {
public void testAddedDeploymentInfo() throws Exception {
GridCacheContext<?, ?> ctx = cacheContext();

if (grid(0).configuration().getMarshaller() instanceof BinaryMarshaller)
assertFalse(ctx.deploymentEnabled());
else {
GridCacheIoManager ioMgr = cacheIoManager();

TestMessage msg = new TestMessage();

assertNull(msg.deployInfo());

msg.addDepInfo = true;

IgniteUtils.invoke(GridCacheIoManager.class, ioMgr, "onSend", msg, grid(1).cluster().localNode().id());

assertNotNull(msg.deployInfo());
}
assertFalse(ctx.deploymentEnabled());
}

/**
Expand All @@ -132,23 +117,7 @@ public void testAddedDeploymentInfo() throws Exception {
public void testAddedDeploymentInfo2() throws Exception {
GridCacheContext<?, ?> ctx = cacheContext();

if (grid(0).configuration().getMarshaller() instanceof BinaryMarshaller)
assertFalse(ctx.deploymentEnabled());
else {
assertTrue(ctx.deploymentEnabled());

GridCacheIoManager ioMgr = cacheIoManager();

TestMessage msg = new TestMessage();

assertNull(msg.deployInfo());

msg.addDepInfo = false;

IgniteUtils.invoke(GridCacheIoManager.class, ioMgr, "onSend", msg, grid(1).cluster().localNode().id());

assertNull(msg.deployInfo());
}
assertFalse(ctx.deploymentEnabled());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition;
import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
import org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory;
Expand Down Expand Up @@ -3460,12 +3459,7 @@ private void checkAffinityMappers(Ignite node) {
assertEquals(i + 10, aff2.partition(k));
assertEquals(i + 10, aff4.partition(k));

int part;

if (node.configuration().getMarshaller() instanceof BinaryMarshaller)
part = func.partition(node.binary().toBinary(k));
else
part = func.partition(k);
int part = func.partition(node.binary().toBinary(k));

assertEquals(part, aff5.partition(k));
assertEquals(part, aff6.partition(k));
Expand Down
Loading

0 comments on commit 439219d

Please sign in to comment.