use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class IgniteClientReconnectApiExceptionTest method doTestIgniteOperationOnDisconnect.
/**
* @param client Client.
* @param ops Operations closures.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void doTestIgniteOperationOnDisconnect(Ignite client, final List<T2<Callable, C1<Object, Boolean>>> ops) throws Exception {
assertNotNull(client.cache(DEFAULT_CACHE_NAME));
final TestTcpDiscoverySpi clientSpi = spi(client);
Ignite srv = clientRouter(client);
TestTcpDiscoverySpi srvSpi = spi(srv);
final CountDownLatch disconnectLatch = new CountDownLatch(1);
final CountDownLatch reconnectLatch = new CountDownLatch(1);
log.info("Block reconnect.");
clientSpi.writeLatch = new CountDownLatch(1);
final List<IgniteInternalFuture> futs = new ArrayList<>();
client.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
info("Disconnected: " + evt);
assertEquals(1, reconnectLatch.getCount());
for (T2<Callable, C1<Object, Boolean>> op : ops) futs.add(GridTestUtils.runAsync(op.get1()));
disconnectLatch.countDown();
} else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
info("Reconnected: " + evt);
reconnectLatch.countDown();
}
return true;
}
}, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
try {
log.info("Fail client.");
srvSpi.failNode(client.cluster().localNode().id(), null);
waitReconnectEvent(disconnectLatch);
assertEquals(ops.size(), futs.size());
for (IgniteInternalFuture<?> fut : futs) assertNotDone(fut);
U.sleep(2000);
for (IgniteInternalFuture<?> fut : futs) assertNotDone(fut);
log.info("Allow reconnect.");
clientSpi.writeLatch.countDown();
waitReconnectEvent(reconnectLatch);
// Check operation after reconnect working.
for (int i = 0; i < futs.size(); i++) {
final int i0 = i;
try {
final Object futRes = futs.get(i0).get(2, SECONDS);
assertTrue(GridTestUtils.runAsync(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return ops.get(i0).get2().apply(futRes);
}
}).get(2, SECONDS));
} catch (IgniteFutureTimeoutCheckedException e) {
e.printStackTrace();
fail("Operation timeout. Iteration: " + i + ".");
}
}
} finally {
clientSpi.writeLatch.countDown();
for (IgniteInternalFuture fut : futs) fut.cancel();
stopAllGrids();
}
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class GridTestUtils method assertOneToOne.
/**
* Asserts that each element in iterable has one-to-one correspondence with a
* predicate from list.
*
* @param it Input iterable of elements.
* @param ps Array of predicates (by number of elements in iterable).
*/
@SuppressWarnings("ConstantConditions")
public static <T> void assertOneToOne(Iterable<T> it, IgnitePredicate<T>... ps) {
Collection<IgnitePredicate<T>> ps0 = new ArrayList<>(Arrays.asList(ps));
Collection<T2<IgnitePredicate<T>, T>> passed = new ArrayList<>();
for (T elem : it) {
for (T2<IgnitePredicate<T>, T> p : passed) {
if (p.get1().apply(elem))
throw new AssertionError("Two elements match one predicate [elem1=" + p.get2() + ", elem2=" + elem + ", pred=" + p.get1() + ']');
}
IgnitePredicate<T> matched = null;
for (IgnitePredicate<T> p : ps0) {
if (p.apply(elem)) {
if (matched != null)
throw new AssertionError("Element matches more than one predicate [elem=" + elem + ", pred1=" + p + ", pred2=" + matched + ']');
matched = p;
}
}
if (// None matched.
matched == null)
throw new AssertionError("The element does not match [elem=" + elem + ", numRemainingPreds=" + ps0.size() + ']');
ps0.remove(matched);
passed.add(new T2<>(matched, elem));
}
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class IgniteCacheExpireAndUpdateConsistencyTest method checkEvents.
/**
* @param updates Cache update.
* @param evts Received events.
* @throws Exception If failed.
*/
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private void checkEvents(ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> updates, final ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> evts) throws Exception {
for (final TestKey key : updates.keySet()) {
final List<T2<TestValue, TestValue>> keyUpdates = updates.get(key);
assert (!F.isEmpty(keyUpdates));
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
List<T2<TestValue, TestValue>> keyEvts = evts.get(key);
if (keyEvts == null)
return false;
synchronized (keyEvts) {
return keyEvts.size() == keyUpdates.size();
}
}
}, 5000);
List<T2<TestValue, TestValue>> keyEvts = evts.get(key);
assertNotNull(keyEvts);
for (int i = 0; i < keyUpdates.size(); i++) {
T2<TestValue, TestValue> update = keyUpdates.get(i);
T2<TestValue, TestValue> evt = keyEvts.get(i);
assertEquals(update.get1(), evt.get1());
assertEquals(update.get2(), evt.get2());
}
}
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class IgfsModeResolverSelfTest method testModesValidation.
/**
* @throws Exception If failed.
*/
public void testModesValidation() throws Exception {
// Another mode inside PRIMARY directory:
try {
IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/"), PRIMARY), new T2<>(new IgfsPath("/a/b/"), DUAL_ASYNC)), new HashSet<IgfsPath>());
fail("IgniteCheckedException expected");
} catch (IgniteCheckedException ignored) {
// No-op.
}
// PRIMARY default mode and non-primary subfolder:
for (IgfsMode m : IgfsMode.values()) {
if (m != IgfsMode.PRIMARY) {
try {
IgfsUtils.preparePathModes(PRIMARY, Arrays.asList(new T2<>(new IgfsPath("/a/"), DUAL_ASYNC)), new HashSet<IgfsPath>());
fail("IgniteCheckedException expected");
} catch (IgniteCheckedException ignored) {
// No-op.
}
}
}
// Duplicated sub-folders should be ignored:
List<T2<IgfsPath, IgfsMode>> modes = IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a"), PRIMARY), new T2<>(new IgfsPath("/c/d/"), PRIMARY), new T2<>(new IgfsPath("/c/d/e/f"), PRIMARY)), new HashSet<IgfsPath>());
assertNotNull(modes);
assertEquals(2, modes.size());
assertEquals(modes, Arrays.asList(new T2<>(new IgfsPath("/c/d/"), PRIMARY), new T2<>(new IgfsPath("/a"), PRIMARY)));
// Non-duplicated sub-folders should not be ignored:
modes = IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), DUAL_SYNC), new T2<>(new IgfsPath("/a/b/c/d"), DUAL_ASYNC)), new HashSet<IgfsPath>());
assertNotNull(modes);
assertEquals(modes.size(), 3);
assertEquals(modes, Arrays.asList(new T2<>(new IgfsPath("/a/b/c/d"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), DUAL_SYNC), new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC)));
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class IgfsModeResolverSelfTest method testDualParentsWithPrimaryChild.
/**
* @throws Exception If failed.
*/
public void testDualParentsWithPrimaryChild() throws Exception {
Set<IgfsPath> set = new HashSet<>();
IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), PRIMARY), new T2<>(new IgfsPath("/a/b/x/y"), PRIMARY), new T2<>(new IgfsPath("/a/b/x/z"), PRIMARY), new T2<>(new IgfsPath("/m"), PRIMARY)), set);
assertEquals(set, new HashSet<IgfsPath>() {
{
add(new IgfsPath("/a/b"));
add(new IgfsPath("/a/b/x"));
add(IgfsPath.ROOT);
}
});
set = new HashSet<>();
IgfsUtils.preparePathModes(DUAL_ASYNC, Arrays.asList(new T2<>(new IgfsPath("/a/b/x/y/z"), PRIMARY), new T2<>(new IgfsPath("/a/b/c"), PRIMARY), new T2<>(new IgfsPath("/a/k"), PRIMARY), new T2<>(new IgfsPath("/a/z"), PRIMARY)), set);
assertEquals(set, new HashSet<IgfsPath>() {
{
add(new IgfsPath("/a/b"));
add(new IgfsPath("/a"));
add(new IgfsPath("/a/b/x/y"));
}
});
}
Aggregations