Skip to content

Commit

Permalink
ignite-2.0 - Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agoncharuk committed Apr 26, 2017
1 parent 4be320a commit c9cd761
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
Expand Up @@ -197,6 +197,9 @@ protected void addOutgoingSignal(String condition) {
outgoingSignals.put(condition, cnt + 1);
}

/**
* @param condition Condition.
*/
protected void addOutgoingSignalAll(String condition) {
outgoingSignals.put(condition, 0);
}
Expand Down Expand Up @@ -329,6 +332,9 @@ protected boolean isLockedLocally(UUID newOwnerID) {
return thisNode.equals(getOwnerNode()) || thisNode.equals(newOwnerID);
}

/**
* @param newOwnerThreadId New owner thread id.
*/
protected void setCurrentOwnerThread(long newOwnerThreadId) {
currentOwnerThreadId = newOwnerThreadId;
}
Expand Down
Expand Up @@ -299,7 +299,9 @@ private static Object appendOrPrepend(Object origVal, Object appendVal,
return col;
}

throw new IgniteCheckedException("Incompatible types [appendVal=" + appendVal + ", old=" + origVal + ']');
throw new IgniteCheckedException("Incompatible types [appendVal=" + appendVal +
",type=" + (appendVal != null ? appendVal.getClass().getSimpleName() : "NULL") + ", old=" + origVal +
",type= " + (origVal != null ? origVal.getClass().getSimpleName() : "NULL") + ']');
}

/**
Expand Down
Expand Up @@ -33,7 +33,6 @@
import org.apache.ignite.IgniteAtomicReference;
import org.apache.ignite.IgniteAtomicSequence;
import org.apache.ignite.IgniteAtomicStamped;
import org.apache.ignite.IgniteCompute;
import org.apache.ignite.IgniteCountDownLatch;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteInterruptedException;
Expand All @@ -44,11 +43,13 @@
import org.apache.ignite.configuration.AtomicConfiguration;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.util.GridLeanSet;
import org.apache.ignite.internal.util.typedef.CA;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.util.typedef.PA;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteCallable;
Expand All @@ -60,6 +61,7 @@
import org.apache.ignite.testframework.GridTestUtils;

import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;

/**
* Failover tests for cache data structures.
Expand Down Expand Up @@ -408,7 +410,7 @@ public void testCountDownLatchTopologyChange() throws Exception {
* @throws Exception If failed.
*/
public void testSemaphoreFailoverSafe() throws Exception {
try (IgniteSemaphore semaphore = grid(0).semaphore(STRUCTURE_NAME, 20, true, true)) {
try (final IgniteSemaphore semaphore = grid(0).semaphore(STRUCTURE_NAME, 20, true, true)) {
Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);

IgniteSemaphore semaphore2 = g.semaphore(STRUCTURE_NAME, 20, true, false);
Expand All @@ -419,7 +421,11 @@ public void testSemaphoreFailoverSafe() throws Exception {

stopGrid(NEW_IGNITE_INSTANCE_NAME);

assertEquals(20, semaphore.availablePermits());
waitForCondition(new PA() {
@Override public boolean apply() {
return semaphore.availablePermits() == 20;
}
}, 2000);
}
}

Expand Down Expand Up @@ -736,10 +742,16 @@ public void testFairReentrantLockConstantMultipleTopologyChangeNonFailoverSafe()
/**
* @throws Exception If failed.
*/
private void doTestReentrantLock(ConstantTopologyChangeWorker topWorker, final boolean failoverSafe, final boolean fair) throws Exception {
try (IgniteLock lock = grid(0).reentrantLock(STRUCTURE_NAME, failoverSafe, fair, true)) {
IgniteInternalFuture<?> fut = topWorker.startChangingTopology(new IgniteClosure<Ignite, Object>() {
@Override public Object apply(Ignite ignite) {
private void doTestReentrantLock(
final ConstantTopologyChangeWorker topWorker,
final boolean failoverSafe,
final boolean fair
) throws Exception {
IgniteEx ig = grid(0);

try (IgniteLock lock = ig.reentrantLock(STRUCTURE_NAME, failoverSafe, fair, true)) {
IgniteInternalFuture<?> fut = topWorker.startChangingTopology(new IgniteClosure<Ignite, Void>() {
@Override public Void apply(Ignite ignite) {
final IgniteLock l = ignite.reentrantLock(STRUCTURE_NAME, failoverSafe, fair, false);

final AtomicBoolean done = new AtomicBoolean(false);
Expand Down Expand Up @@ -767,33 +779,33 @@ private void doTestReentrantLock(ConstantTopologyChangeWorker topWorker, final b
});

while (!fut.isDone()) {
while (true) {
try {
lock.lock();
}
catch (IgniteException e) {
// Exception may happen in non-failoversafe mode.
if (failoverSafe)
throw e;
}
finally {
// Broken lock cannot be used in non-failoversafe mode.
if(!lock.isBroken() || failoverSafe) {
assertTrue(lock.isHeldByCurrentThread());
try {
lock.lock();
}
catch (IgniteException e) {
// Exception may happen in non-failoversafe mode.
if (failoverSafe)
throw e;
}
finally {
// Broken lock cannot be used in non-failoversafe mode.
if(!lock.isBroken() || failoverSafe) {
assertTrue(lock.isHeldByCurrentThread());

lock.unlock();
lock.unlock();

assertFalse(lock.isHeldByCurrentThread());
}
break;
assertFalse(lock.isHeldByCurrentThread());
}
}
}

fut.get();

for (Ignite g : G.allGrids())
assertFalse(g.reentrantLock(STRUCTURE_NAME, failoverSafe, fair, false).isHeldByCurrentThread());
for (Ignite g : G.allGrids()){
IgniteLock l = g.reentrantLock(STRUCTURE_NAME, failoverSafe, fair, false);

assertTrue(g.name(), !l.isHeldByCurrentThread() || lock.isBroken());
}
}
}

Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.apache.ignite.events.Event;
import org.apache.ignite.events.EventType;
import org.apache.ignite.internal.util.lang.GridAbsPredicate;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiPredicate;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.testframework.GridTestUtils;
Expand Down Expand Up @@ -366,7 +367,9 @@ public void testFourNodesKillRestartZookeeper() throws Exception {
try {
return 0 == zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size();
}
catch (Exception ignored) {
catch (Exception e) {
U.error(log, "Failed to wait for zk condition", e);

return false;
}
}
Expand Down

0 comments on commit c9cd761

Please sign in to comment.