Skip to content
Permalink
Browse files
IGNITE-14251 Refactors proxy classes names and reuse cache proxies in…
… spring-tx tests. (#47)
  • Loading branch information
ololo3000 committed Feb 27, 2021
1 parent d9559d4 commit f99e571924a8773a08e5b3ac901fe794eb25693f
Showing 19 changed files with 70 additions and 128 deletions.
@@ -24,7 +24,7 @@
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.configuration.ClientConfiguration;
import org.apache.ignite.internal.util.typedef.internal.A;
import org.apache.ignite.springdata.proxy.IgniteCacheClientProxy;
import org.apache.ignite.springdata.proxy.IgniteClientCacheProxy;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationListener;
@@ -169,7 +169,7 @@ public IgniteClientSpringCacheManager setDynamicCacheConfiguration(ClientCacheCo

ClientCache<Object, Object> cache = cli.getOrCreateCache(ccfg.setName(name));

return new SpringCache(new IgniteCacheClientProxy<>(cache), this);
return new SpringCache(new IgniteClientCacheProxy<>(cache), this);
}

/** {@inheritDoc} */
@@ -29,7 +29,7 @@
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.springdata.proxy.IgniteCacheProxyImpl;
import org.apache.ignite.springdata.proxy.IgniteNodeCacheProxy;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -355,7 +355,7 @@ else if (cfg != null)
? ignite.getOrCreateCache(cacheCfg, nearCacheCfg)
: ignite.getOrCreateCache(cacheCfg);

return new SpringCache(new IgniteCacheProxyImpl<>(cache), this);
return new SpringCache(new IgniteNodeCacheProxy<>(cache), this);
}

/** {@inheritDoc} */
@@ -20,7 +20,7 @@
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.springdata.proxy.IgniteCacheProxyImpl;
import org.apache.ignite.springdata.proxy.IgniteNodeCacheProxy;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;

@@ -59,7 +59,7 @@ public class SpringCacheTest extends GridCommonAbstractTest {

cacheName = String.valueOf(System.currentTimeMillis());
nativeCache = ignite.getOrCreateCache(cacheName);
springCache = new SpringCache(new IgniteCacheProxyImpl<>(nativeCache), null);
springCache = new SpringCache(new IgniteNodeCacheProxy<>(nativeCache), null);
}

/** {@inheritDoc} */
@@ -48,7 +48,7 @@
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cache.query.TextQuery;
import org.apache.ignite.springdata.proxy.IgniteCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteCacheClientProxy;
import org.apache.ignite.springdata.proxy.IgniteClientCacheProxy;
import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.springdata20.repository.config.DynamicQueryConfig;
@@ -346,7 +346,7 @@ public IgniteRepositoryQuery(
qryCursor = cache.query(iQry);
}
catch (IllegalArgumentException e) {
if (cache instanceof IgniteCacheClientProxy) {
if (cache instanceof IgniteClientCacheProxy) {
throw new IllegalStateException(String.format("Query of type %s is not supported by thin client." +
" Check %s#%s method configuration or use Ignite node instance to connect to the Ignite cluster.",
iQry.getClass().getSimpleName(), mtd.getDeclaringClass().getName(), mtd.getName()), e);
@@ -30,9 +30,9 @@
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CachePeekMode;
import org.apache.ignite.springdata.proxy.IgniteCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteCacheProxyImpl;
import org.apache.ignite.springdata.proxy.IgniteNodeCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteProxy;
import org.apache.ignite.springdata.proxy.IgniteProxyImpl;
import org.apache.ignite.springdata.proxy.IgniteNodeProxy;
import org.apache.ignite.springdata20.repository.IgniteRepository;
import org.apache.ignite.springdata20.repository.config.RepositoryConfig;
import org.jetbrains.annotations.Nullable;
@@ -76,16 +76,16 @@ public IgniteRepositoryImpl(IgniteProxy ignite, IgniteCacheProxy<K, V> cache) {

/** {@inheritDoc} */
@Override public IgniteCache<K, V> cache() {
if (cache instanceof IgniteCacheProxyImpl)
return ((IgniteCacheProxyImpl<K, V>)cache).delegate();
if (cache instanceof IgniteNodeCacheProxy)
return ((IgniteNodeCacheProxy<K, V>)cache).delegate();

throw new UnsupportedOperationException(UNSUPPORTED_ERR_MSG);
}

/** {@inheritDoc} */
@Override public Ignite ignite() {
if (ignite instanceof IgniteProxyImpl)
return ((IgniteProxyImpl)ignite).delegate();
if (ignite instanceof IgniteNodeProxy)
return ((IgniteNodeProxy)ignite).delegate();

throw new UnsupportedOperationException(UNSUPPORTED_ERR_MSG);
}
@@ -48,7 +48,7 @@
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cache.query.TextQuery;
import org.apache.ignite.springdata.proxy.IgniteCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteCacheClientProxy;
import org.apache.ignite.springdata.proxy.IgniteClientCacheProxy;
import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.springdata22.repository.config.DynamicQueryConfig;
@@ -346,7 +346,7 @@ public IgniteRepositoryQuery(
qryCursor = cache.query(iQry);
}
catch (IllegalArgumentException e) {
if (cache instanceof IgniteCacheClientProxy) {
if (cache instanceof IgniteClientCacheProxy) {
throw new IllegalStateException(String.format("Query of type %s is not supported by thin client." +
" Check %s#%s method configuration or use Ignite node instance to connect to the Ignite cluster.",
iQry.getClass().getSimpleName(), mtd.getDeclaringClass().getName(), mtd.getName()), e);
@@ -30,9 +30,9 @@
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CachePeekMode;
import org.apache.ignite.springdata.proxy.IgniteCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteCacheProxyImpl;
import org.apache.ignite.springdata.proxy.IgniteNodeCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteProxy;
import org.apache.ignite.springdata.proxy.IgniteProxyImpl;
import org.apache.ignite.springdata.proxy.IgniteNodeProxy;
import org.apache.ignite.springdata22.repository.IgniteRepository;
import org.apache.ignite.springdata22.repository.config.RepositoryConfig;
import org.jetbrains.annotations.Nullable;
@@ -76,16 +76,16 @@ public IgniteRepositoryImpl(IgniteProxy ignite, IgniteCacheProxy<K, V> cache) {

/** {@inheritDoc} */
@Override public IgniteCache<K, V> cache() {
if (cache instanceof IgniteCacheProxyImpl)
return ((IgniteCacheProxyImpl<K, V>)cache).delegate();
if (cache instanceof IgniteNodeCacheProxy)
return ((IgniteNodeCacheProxy<K, V>)cache).delegate();

throw new UnsupportedOperationException(UNSUPPORTED_ERR_MSG);
}

/** {@inheritDoc} */
@Override public Ignite ignite() {
if (ignite instanceof IgniteProxyImpl)
return ((IgniteProxyImpl)ignite).delegate();
if (ignite instanceof IgniteNodeProxy)
return ((IgniteNodeProxy)ignite).delegate();

throw new UnsupportedOperationException(UNSUPPORTED_ERR_MSG);
}
@@ -19,12 +19,12 @@

import org.apache.ignite.Ignite;

/** Extends {@link IgniteProxyImpl} with the ability to close underlying Ignite instance. */
public class ClosableIgniteProxyImpl extends IgniteProxyImpl implements AutoCloseable {
/** Extends {@link IgniteNodeProxy} with the ability to close underlying Ignite instance. */
public class ClosableIgniteNodeProxy extends IgniteNodeProxy implements AutoCloseable {
/**
* @param ignite Ignite instance.
*/
public ClosableIgniteProxyImpl(Ignite ignite) {
public ClosableIgniteNodeProxy(Ignite ignite) {
super(ignite);
}

@@ -31,12 +31,12 @@
import org.jetbrains.annotations.NotNull;

/** Implementation of {@link IgniteCacheProxy} that provides access to Ignite cache through {@link ClientCache} instance. */
public class IgniteCacheClientProxy<K, V> implements IgniteCacheProxy<K, V> {
public class IgniteClientCacheProxy<K, V> implements IgniteCacheProxy<K, V> {
/** {@link ClientCache} instance to which operations are delegated. */
private final ClientCache<K, V> cache;

/** */
public IgniteCacheClientProxy(ClientCache<K, V> cache) {
public IgniteClientCacheProxy(ClientCache<K, V> cache) {
this.cache = cache;
}

@@ -82,7 +82,7 @@ public IgniteCacheClientProxy(ClientCache<K, V> cache) {

/** {@inheritDoc} */
@Override public IgniteCacheProxy<K, V> withExpiryPolicy(ExpiryPolicy expirePlc) {
return new IgniteCacheClientProxy<>(cache.withExpirePolicy(expirePlc));
return new IgniteClientCacheProxy<>(cache.withExpirePolicy(expirePlc));
}

/** {@inheritDoc} */
@@ -32,12 +32,12 @@ public IgniteClientProxy(IgniteClient cli) {

/** {@inheritDoc} */
@Override public <K, V> IgniteCacheProxy<K, V> getOrCreateCache(String name) {
return new IgniteCacheClientProxy<>(cli.getOrCreateCache(name));
return new IgniteClientCacheProxy<>(cli.getOrCreateCache(name));
}

/** {@inheritDoc} */
@Override public <K, V> IgniteCacheProxy<K, V> cache(String name) {
return new IgniteCacheClientProxy<>(cli.cache(name));
return new IgniteClientCacheProxy<>(cli.cache(name));
}

/** {@inheritDoc} */
@@ -31,12 +31,12 @@
import org.jetbrains.annotations.NotNull;

/** Implementation of {@link IgniteCacheProxy} that provides access to Ignite cache through {@link IgniteCache} instance. */
public class IgniteCacheProxyImpl<K, V> implements IgniteCacheProxy<K, V> {
public class IgniteNodeCacheProxy<K, V> implements IgniteCacheProxy<K, V> {
/** {@link IgniteCache} instance to which operations are delegated. */
private final IgniteCache<K, V> cache;

/** */
public IgniteCacheProxyImpl(IgniteCache<K, V> cache) {
public IgniteNodeCacheProxy(IgniteCache<K, V> cache) {
this.cache = cache;
}

@@ -82,7 +82,7 @@ public IgniteCacheProxyImpl(IgniteCache<K, V> cache) {

/** {@inheritDoc} */
@Override public IgniteCacheProxy<K, V> withExpiryPolicy(ExpiryPolicy expirePlc) {
return new IgniteCacheProxyImpl<>(cache.withExpiryPolicy(expirePlc));
return new IgniteNodeCacheProxy<>(cache.withExpiryPolicy(expirePlc));
}

/** {@inheritDoc} */
@@ -107,7 +107,7 @@ public IgniteCacheProxyImpl(IgniteCache<K, V> cache) {

/** {@inheritDoc} */
@Override public IgniteCacheProxy<K, V> withSkipStore() {
return new IgniteCacheProxyImpl<>(cache.withSkipStore());
return new IgniteNodeCacheProxy<>(cache.withSkipStore());
}

/** {@inheritDoc} */
@@ -22,25 +22,25 @@
import org.apache.ignite.IgniteCache;

/** Implementation of {@link IgniteProxy} that provides access to Ignite cluster through {@link Ignite} instance. */
public class IgniteProxyImpl implements IgniteProxy {
public class IgniteNodeProxy implements IgniteProxy {
/** {@link Ignite} instance to which operations are delegated. */
protected final Ignite ignite;

/** */
public IgniteProxyImpl(Ignite ignite) {
public IgniteNodeProxy(Ignite ignite) {
this.ignite = ignite;
}

/** {@inheritDoc} */
@Override public <K, V> IgniteCacheProxy<K, V> getOrCreateCache(String name) {
return new IgniteCacheProxyImpl<>(ignite.getOrCreateCache(name));
return new IgniteNodeCacheProxy<>(ignite.getOrCreateCache(name));
}

/** {@inheritDoc} */
@Override public <K, V> IgniteCacheProxy<K, V> cache(String name) {
IgniteCache<K, V> cache = ignite.cache(name);

return cache == null ? null : new IgniteCacheProxyImpl<>(cache);
return cache == null ? null : new IgniteNodeCacheProxy<>(cache);
}

/** @return {@link Ignite} instance to which operations are delegated. */
@@ -56,7 +56,7 @@ public Ignite delegate() {
if (other == null || getClass() != other.getClass())
return false;

return Objects.equals(ignite, ((IgniteProxyImpl)other).ignite);
return Objects.equals(ignite, ((IgniteNodeProxy)other).ignite);
}

/** {@inheritDoc} */
@@ -47,19 +47,19 @@ public interface IgniteProxy {
*/
public static IgniteProxy of(Object connObj) {
if (connObj instanceof Ignite)
return new IgniteProxyImpl((Ignite)connObj);
return new IgniteNodeProxy((Ignite)connObj);
else if (connObj instanceof IgniteConfiguration) {
try {
return new IgniteProxyImpl(Ignition.ignite(((IgniteConfiguration)connObj).getIgniteInstanceName()));
return new IgniteNodeProxy(Ignition.ignite(((IgniteConfiguration)connObj).getIgniteInstanceName()));
}
catch (Exception ignored) {
// No-op.
}

return new ClosableIgniteProxyImpl(Ignition.start((IgniteConfiguration)connObj));
return new ClosableIgniteNodeProxy(Ignition.start((IgniteConfiguration)connObj));
}
else if (connObj instanceof String)
return new ClosableIgniteProxyImpl(Ignition.start((String)connObj));
return new ClosableIgniteNodeProxy(Ignition.start((String)connObj));
else if (connObj instanceof IgniteClient)
return new IgniteClientProxy((IgniteClient)connObj);
else if (connObj instanceof ClientConfiguration)
@@ -76,6 +76,13 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring-data-commons</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
@@ -17,9 +17,9 @@

package org.apache.ignite.transactions.spring;

import org.apache.ignite.springdata.proxy.IgniteCacheProxy;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.apache.ignite.transactions.Transaction;
import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
import org.junit.Test;
import org.springframework.transaction.IllegalTransactionStateException;
import org.springframework.transaction.InvalidIsolationLevelException;
@@ -33,7 +33,7 @@ public abstract class GridSpringTransactionManagerAbstractTest extends GridCommo
protected static final String CACHE_NAME = "testCache";

/** */
public abstract CacheProxy<Integer, String> cache();
public abstract IgniteCacheProxy<Integer, String> cache();

/** */
public abstract GridSpringTransactionService service();
@@ -20,8 +20,8 @@
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
import org.apache.ignite.transactions.spring.GridSpringTransactionService.IgniteCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteNodeCacheProxy;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

@@ -46,8 +46,8 @@ public class GridSpringTransactionManagerSelfTest extends GridSpringTransactionM
return cfg;
}

@Override public CacheProxy<Integer, String> cache() {
return new IgniteCacheProxy<>(grid().cache(CACHE_NAME));
@Override public IgniteCacheProxy<Integer, String> cache() {
return new IgniteNodeCacheProxy<>(grid().cache(CACHE_NAME));
}

@Override public GridSpringTransactionService service() {
@@ -18,8 +18,8 @@
package org.apache.ignite.transactions.spring;

import org.apache.ignite.Ignite;
import org.apache.ignite.transactions.spring.GridSpringTransactionService.CacheProxy;
import org.apache.ignite.transactions.spring.GridSpringTransactionService.IgniteCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteCacheProxy;
import org.apache.ignite.springdata.proxy.IgniteNodeCacheProxy;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

@@ -31,8 +31,8 @@ public class GridSpringTransactionManagerSpringBeanSelfTest extends GridSpringTr
/** */
private GridSpringTransactionService service;

@Override public CacheProxy<Integer, String> cache() {
return new IgniteCacheProxy<>(ignite.cache(CACHE_NAME));
@Override public IgniteCacheProxy<Integer, String> cache() {
return new IgniteNodeCacheProxy<>(ignite.cache(CACHE_NAME));
}

@Override public GridSpringTransactionService service() {

0 comments on commit f99e571

Please sign in to comment.