use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage 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 {
applyDiscoveryHook = true;
discoveryHook = new DiscoveryHook() {
@Override
public void beforeDiscovery(DiscoveryCustomMessage customMsg) {
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 = startClientGrid(clientName);
applyDiscoveryHook = false;
return client;
}
use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage 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.
*/
@Test
public void testReadRequestBlockedOnUpdatingMetadata() throws Exception {
final CyclicBarrier barrier = new CyclicBarrier(2);
applyDiscoveryHook = false;
final Ignite ignite0 = startGrid(0);
final Ignite ignite1 = startGrid(1);
final GridFutureAdapter finishFut = new GridFutureAdapter();
applyDiscoveryHook = true;
discoveryHook = new DiscoveryHook() {
private volatile IgniteEx ignite;
@Override
public void beforeDiscovery(DiscoveryCustomMessage customMsg) {
if (finishFut.isDone())
return;
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 {
barrier.await(MAX_AWAIT, TimeUnit.MILLISECONDS);
Map syncMap = U.field(transport, "syncMap");
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return syncMap.size() == 1;
}
}, MAX_AWAIT);
assertEquals("unexpected size of syncMap: ", 1, syncMap.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);
finishFut.onDone();
} catch (Throwable t) {
finishFut.onDone(t);
}
}
}
}
@Override
public void ignite(IgniteEx ignite) {
this.ignite = ignite;
}
};
final IgniteEx ignite2 = startGrid(2);
discoveryHook.ignite(ignite2);
// Unfinished PME may affect max await timeout.
awaitPartitionMapExchange();
// Update metadata (version 1).
ignite0.executorService(ignite0.cluster().forLocal()).submit(new Runnable() {
@Override
public void run() {
addIntField(ignite0, "f1", 101, 1);
}
}).get();
// Update metadata (version 2).
ignite1.executorService(ignite1.cluster().forLocal()).submit(new Runnable() {
@Override
public void run() {
addStringField(ignite1, "f2", "str", 2);
}
});
// Read metadata.
IgniteFuture readFut = ignite2.compute(ignite2.cluster().forLocal()).callAsync(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
barrier.await(MAX_AWAIT, TimeUnit.MILLISECONDS);
return ((BinaryObject) ignite2.cache(DEFAULT_CACHE_NAME).withKeepBinary().get(1)).field("f1");
}
});
finishFut.get(MAX_AWAIT);
assertEquals(101, readFut.get(MAX_AWAIT));
}
use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.
the class AbstractBinaryMetadataRegistrationTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
((TestTcpDiscoverySpi) cfg.getDiscoverySpi()).discoveryHook(new DiscoveryHook() {
@Override
public void beforeDiscovery(DiscoveryCustomMessage customMsg) {
if (customMsg instanceof MetadataUpdateProposedMessage)
proposeMsgNum.incrementAndGet();
}
});
cfg.setCacheConfiguration(cacheConfiguration());
return cfg;
}
use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.
the class DiscoverySpiTestListener method beforeSendCustomEvent.
/**
* {@inheritDoc}
*/
@Override
public boolean beforeSendCustomEvent(DiscoverySpi spi, IgniteLogger log, DiscoverySpiCustomMessage msg) {
this.spi = spi;
this.log = log;
synchronized (mux) {
if (blockCustomEvtCls != null) {
DiscoveryCustomMessage msg0 = GridTestUtils.getFieldValue(msg, "delegate");
if (blockCustomEvtCls.contains(msg0.getClass())) {
log.info("Block custom message: " + msg0);
blockedMsgs.add(msg);
mux.notifyAll();
return false;
}
}
}
return true;
}
use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.
the class CacheBlockOnReadAbstractTest method testUpdateBaselineTopologyTransactionalReplicated.
/**
* @throws Exception If failed.
*/
@Params(timeout = 5000L, atomicityMode = TRANSACTIONAL, cacheMode = REPLICATED)
@Test
public void testUpdateBaselineTopologyTransactionalReplicated() throws Exception {
doTest(asMessagePredicate(discoEvt -> {
if (discoEvt instanceof DiscoveryCustomEvent) {
DiscoveryCustomEvent discoCustomEvt = (DiscoveryCustomEvent) discoEvt;
DiscoveryCustomMessage customMsg = discoCustomEvt.customMessage();
return customMsg instanceof ChangeGlobalStateMessage;
}
return false;
}), () -> {
startNodesInClientMode(false);
IgniteEx ignite = startGrid(UUID.randomUUID().toString());
baseline.get(0).cluster().setBaselineTopology(baseline.get(0).context().discovery().topologyVersion());
baseline.add(ignite);
});
}
Aggregations