Skip to content

Commit

Permalink
IGNITE-51 - Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Goncharuk committed Feb 10, 2015
1 parent dfba5bf commit df777c3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
Expand Up @@ -273,14 +273,28 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana

U.join(exchWorker, log);

exchFuts = null;

ResendTimeoutObject resendTimeoutObj = pendingResend.getAndSet(null);

if (resendTimeoutObj != null)
cctx.time().removeTimeoutObject(resendTimeoutObj);
}

/** {@inheritDoc} */
@SuppressWarnings("LockAcquiredButNotSafelyReleased")
@Override protected void stop0(boolean cancel) {
super.stop0(cancel);

// Do not allow any activity in exchange manager after stop.
busyLock.writeLock().lock();

exchFuts = null;
}

/**
* @param cacheId Cache ID.
* @param exchId Exchange ID.
* @return Topology.
*/
public GridDhtPartitionTopology<K, V> clientTopology(int cacheId, GridDhtPartitionExchangeId exchId) {
GridClientPartitionTopology<K, V> top = clientTops.get(cacheId);

Expand Down
Expand Up @@ -18,6 +18,7 @@
package org.apache.ignite.internal.processors.cache;

import org.apache.ignite.cache.affinity.*;
import org.apache.ignite.testframework.*;
import org.apache.ignite.testframework.junits.common.*;

import java.util.*;
Expand All @@ -26,13 +27,25 @@
* Test affinity mapper.
*/
public class GridCacheAffinityMapperSelfTest extends GridCommonAbstractTest {
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
startGrid();
}

/** {@inheritDoc} */
@Override protected void afterTestsStopped() throws Exception {
stopAllGrids();
}

/**
*
*/
public void testMethodAffinityMapper() {
CacheAffinityKeyMapper mapper =
new GridCacheDefaultAffinityKeyMapper();

GridTestUtils.setFieldValue(mapper, "ignite", grid());

List<CacheAffinityKey<Integer>> keys = new ArrayList<>();

for (int i = 1; i <= 10; i++)
Expand All @@ -57,6 +70,8 @@ public void testFieldAffinityMapper() {
CacheAffinityKeyMapper mapper =
new GridCacheDefaultAffinityKeyMapper();

GridTestUtils.setFieldValue(mapper, "ignite", grid());

List<FieldAffinityKey<Integer>> keys = new ArrayList<>();

for (int i = 1; i <= 10; i++)
Expand All @@ -81,6 +96,8 @@ public void testFieldAffinityMapperWithWrongClass() {
CacheAffinityKeyMapper mapper =
new GridCacheDefaultAffinityKeyMapper();

GridTestUtils.setFieldValue(mapper, "ignite", grid());

FieldNoAffinityKey key = new FieldNoAffinityKey();
Object mapped = mapper.affinityKey(key);
assertEquals(key, mapped);
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.apache.ignite.internal.processors.cache.distributed.near.*;
import org.apache.ignite.testframework.*;

import javax.cache.*;
import java.util.*;
import java.util.concurrent.*;

Expand Down Expand Up @@ -70,6 +71,23 @@ protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
return ccfg;
}

/**
* @throws Exception If failed.
*/
public void testLock() throws Exception {
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
return jcache().lock("1").tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
}, CacheException.class, "Locks are not supported");

GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
return jcache().lockAll(Collections.singleton("1")).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
}, CacheException.class, "Locks are not supported");
}

/**
* @throws Exception In case of error.
*/
Expand Down
Expand Up @@ -17,19 +17,12 @@

package org.apache.ignite.internal.processors.cache.distributed.near;

import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.internal.processors.cache.distributed.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.testframework.*;
import org.apache.log4j.*;

import javax.cache.*;
import java.util.*;
import java.util.concurrent.*;

import static org.apache.ignite.cache.CacheMode.*;

/**
Expand All @@ -56,31 +49,4 @@ public class GridCachePartitionedLockSelfTest extends GridCacheLockAbstractTest
@Override protected boolean isPartitioned() {
return true;
}

/**
* @throws IgniteCheckedException If failed.
*/
public void testLockAtomicCache() throws Exception {
IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setGridName(getTestGridName(0));
cfg.setClientConnectionConfiguration(null);
cfg.setCacheConfiguration(new CacheConfiguration());

final Ignite g0 = G.start(cfg);

final IgniteCache<Object, Object> cache = g0.jcache(null);

GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
return cache.lock(1).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
}, CacheException.class, "Locks are not supported");

GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
return cache.lockAll(Collections.singleton(1)).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
}, CacheException.class, "Locks are not supported");
}
}

0 comments on commit df777c3

Please sign in to comment.