use of org.apache.ignite.testframework.GridTestUtils.DiscoveryHook in project ignite by apache.
the class BinaryMetadataUpdatesFlowTest method startListening.
/**
* @param idx Index.
* @param deafClient Deaf client.
* @param observedIds Observed ids.
*/
private void startListening(int idx, boolean deafClient, Set<Integer> observedIds) throws Exception {
clientMode = true;
ContinuousQuery qry = new ContinuousQuery();
qry.setLocalListener(new CQListener(observedIds));
if (deafClient) {
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);
}
}
};
IgniteEx client = startGrid(idx);
client.cache(DEFAULT_CACHE_NAME).withKeepBinary().query(qry);
} else {
applyDiscoveryHook = false;
IgniteEx client = startGrid(idx);
client.cache(DEFAULT_CACHE_NAME).withKeepBinary().query(qry);
}
}
use of org.apache.ignite.testframework.GridTestUtils.DiscoveryHook in project ignite by apache.
the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
if (applyDiscoveryHook) {
final DiscoveryHook hook = discoveryHook != null ? discoveryHook : new DiscoveryHook();
cfg.setDiscoverySpi(new TcpDiscoverySpi() {
@Override
public void setListener(@Nullable DiscoverySpiListener lsnr) {
super.setListener(DiscoverySpiListenerWrapper.wrap(lsnr, hook));
}
});
}
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
cfg.setMarshaller(new BinaryMarshaller());
cfg.setClientMode(clientMode);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(CacheMode.REPLICATED);
cfg.setCacheConfiguration(ccfg);
return cfg;
}
use of org.apache.ignite.testframework.GridTestUtils.DiscoveryHook 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.testframework.GridTestUtils.DiscoveryHook 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;
}
use of org.apache.ignite.testframework.GridTestUtils.DiscoveryHook in project ignite by apache.
the class BinaryMetadataUpdatesFlowTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
cfg.setPeerClassLoadingEnabled(false);
if (applyDiscoveryHook) {
final DiscoveryHook hook = discoveryHook != null ? discoveryHook : new DiscoveryHook();
TcpDiscoverySpi discoSpi = new TcpDiscoverySpi() {
@Override
public void setListener(@Nullable DiscoverySpiListener lsnr) {
super.setListener(GridTestUtils.DiscoverySpiListenerWrapper.wrap(lsnr, hook));
}
};
cfg.setDiscoverySpi(discoSpi);
cfg.setMetricsUpdateFrequency(1000);
}
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
cfg.setMarshaller(new BinaryMarshaller());
cfg.setClientMode(clientMode);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(CacheMode.REPLICATED);
cfg.setCacheConfiguration(ccfg);
return cfg;
}
Aggregations