use of org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage in project ignite by apache.
the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method testReadRequestBlockedOnUpdatingMetadata.
/**
* Verifies that if thread tries to read metadata with ongoing update it gets blocked
* until acknowledge message arrives.
*/
public void testReadRequestBlockedOnUpdatingMetadata() throws Exception {
applyDiscoveryHook = true;
discoveryHook = new DiscoveryHook() {
@Override
public void handleDiscoveryMessage(DiscoverySpiCustomMessage msg) {
DiscoveryCustomMessage customMsg = msg == null ? null : (DiscoveryCustomMessage) IgniteUtils.field(msg, "delegate");
if (customMsg instanceof MetadataUpdateAcceptedMessage) {
if (((MetadataUpdateAcceptedMessage) customMsg).typeId() == BINARY_TYPE_ID)
try {
Thread.sleep(300);
} catch (InterruptedException ignored) {
// No-op.
}
}
}
};
final IgniteEx ignite0 = startGrid(0);
applyDiscoveryHook = false;
final IgniteEx ignite1 = startGrid(1);
final ErrorHolder errorHolder = new ErrorHolder();
applyDiscoveryHook = true;
discoveryHook = new DiscoveryHook() {
private volatile IgniteEx ignite;
@Override
public void handleDiscoveryMessage(DiscoverySpiCustomMessage msg) {
DiscoveryCustomMessage customMsg = msg == null ? null : (DiscoveryCustomMessage) IgniteUtils.field(msg, "delegate");
if (customMsg instanceof MetadataUpdateAcceptedMessage) {
MetadataUpdateAcceptedMessage acceptedMsg = (MetadataUpdateAcceptedMessage) customMsg;
if (acceptedMsg.typeId() == BINARY_TYPE_ID && acceptedMsg.acceptedVersion() == 2) {
Object binaryProc = U.field(ignite.context(), "cacheObjProc");
Object transport = U.field(binaryProc, "transport");
try {
Map syncMap = U.field(transport, "syncMap");
int size = syncMap.size();
assertEquals("unexpected size of syncMap: ", 1, size);
Object syncKey = syncMap.keySet().iterator().next();
int typeId = U.field(syncKey, "typeId");
assertEquals("unexpected typeId: ", BINARY_TYPE_ID, typeId);
int ver = U.field(syncKey, "ver");
assertEquals("unexpected pendingVersion: ", 2, ver);
} catch (AssertionFailedError err) {
errorHolder.error(err);
}
}
}
}
@Override
public void ignite(IgniteEx ignite) {
this.ignite = ignite;
}
};
final IgniteEx ignite2 = startGrid(2);
discoveryHook.ignite(ignite2);
ignite0.executorService().submit(new Runnable() {
@Override
public void run() {
addIntField(ignite0, "f1", 101, 1);
}
}).get();
UUID id2 = ignite2.localNode().id();
ClusterGroup cg2 = ignite2.cluster().forNodeId(id2);
Future<?> fut = ignite1.executorService().submit(new Runnable() {
@Override
public void run() {
LATCH1.countDown();
addStringField(ignite1, "f2", "str", 2);
}
});
ignite2.compute(cg2).withAsync().call(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
try {
LATCH1.await();
} catch (InterruptedException ignored) {
// No-op.
}
Object fieldVal = ((BinaryObject) ignite2.cache(DEFAULT_CACHE_NAME).withKeepBinary().get(1)).field("f1");
return fieldVal;
}
});
fut.get();
if (!errorHolder.isEmpty())
errorHolder.fail();
}
use of org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage in project ignite by apache.
the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method startDeafClient.
/**
* Starts client node that skips <b>MetadataUpdateProposedMessage</b> and <b>MetadataUpdateAcceptedMessage</b>
* messages.
*
* @param clientName name of client node.
*/
private Ignite startDeafClient(String clientName) throws Exception {
clientMode = true;
applyDiscoveryHook = true;
discoveryHook = new DiscoveryHook() {
@Override
public void handleDiscoveryMessage(DiscoverySpiCustomMessage msg) {
DiscoveryCustomMessage customMsg = msg == null ? null : (DiscoveryCustomMessage) IgniteUtils.field(msg, "delegate");
if (customMsg instanceof MetadataUpdateProposedMessage) {
if (((MetadataUpdateProposedMessage) customMsg).typeId() == BINARY_TYPE_ID)
GridTestUtils.setFieldValue(customMsg, "typeId", 1);
} else if (customMsg instanceof MetadataUpdateAcceptedMessage) {
if (((MetadataUpdateAcceptedMessage) customMsg).typeId() == BINARY_TYPE_ID)
GridTestUtils.setFieldValue(customMsg, "typeId", 1);
}
}
};
Ignite client = startGrid(clientName);
clientMode = false;
applyDiscoveryHook = false;
return client;
}
Aggregations