use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridRuntimeExceptionSelfTest method testResultFailed.
/**
* @throws Exception If failed.
*/
public void testResultFailed() throws Exception {
Ignite ignite = G.ignite(getTestIgniteInstanceName());
ignite.compute().localDeployTask(GridTaskFailedTestTask.class, GridTaskFailedTestTask.class.getClassLoader());
ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), GridTaskFailedTestTask.class.getName(), FailType.RESULT);
try {
fut.get();
assert false;
} catch (IgniteException e) {
info("Got expected grid exception: " + e);
}
IgniteUuid sesId = fut.getTaskSession().getId();
// Query for correct events.
List<Event> evts = ignite.events().remoteQuery(new TaskFailedEventFilter(sesId), 0);
assert evts.size() == 1;
info("Task failed event: " + evts.get(0));
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class IgfsAbstractSelfTest method testAppendDeleteParentNoClose.
/**
* Test delete on the file parent when it was opened for write(append) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testAppendDeleteParentNoClose() throws Exception {
if (mode != PRIMARY)
return;
if (appendSupported()) {
create(igfs, paths(DIR, SUBDIR), null);
createFile(igfs, FILE, false);
IgfsOutputStream os = null;
IgniteUuid id = null;
try {
id = igfs.context().meta().fileId(FILE);
os = igfs.append(FILE, false);
// Since GG-4911 we allow deletes in this case.
boolean del = igfs.delete(SUBDIR, true);
assertTrue(del);
assertFalse(igfs.exists(FILE));
// id still exists in meta cache since
assertTrue(igfs.context().meta().exists(id));
// it is locked for writing and just moved to TRASH.
// Delete worker cannot delete it for that reason.
os.write(chunk);
os.close();
} finally {
U.closeQuiet(os);
}
assert id != null;
final IgniteUuid id0 = id;
// Delete worker should delete the file once its output stream is finally closed:
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
return !igfs.context().meta().exists(id0);
} catch (IgniteCheckedException ice) {
throw new IgniteException(ice);
}
}
}, 5_000L);
}
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class IgfsDataManagerSelfTest method testAffinityFileMap.
/** @throws Exception If failed. */
public void testAffinityFileMap() throws Exception {
int blockSize = BLOCK_SIZE;
long t = System.currentTimeMillis();
IgfsEntryInfo info = IgfsUtils.createFile(IgniteUuid.randomUuid(), blockSize, 1024 * 1024, null, null, false, null, t, t);
IgniteUuid affKey = IgniteUuid.randomUuid();
IgfsFileMap map = new IgfsFileMap();
map.addRange(new IgfsFileAffinityRange(3 * BLOCK_SIZE, 5 * BLOCK_SIZE - 1, affKey));
map.addRange(new IgfsFileAffinityRange(13 * BLOCK_SIZE, 17 * BLOCK_SIZE - 1, affKey));
info = info.fileMap(map);
Collection<IgfsBlockLocation> affinity = mgr.affinity(info, 0, info.length());
checkAffinity(blockSize, info, affinity);
// Check from middle of range.
affinity = mgr.affinity(info, 3 * BLOCK_SIZE + BLOCK_SIZE / 2, info.length());
checkAffinity(blockSize, info, affinity);
// Check from middle of last range.
affinity = mgr.affinity(info, 14 * BLOCK_SIZE, info.length());
checkAffinity(blockSize, info, affinity);
// Check inside one range.
affinity = mgr.affinity(info, 14 * BLOCK_SIZE, 2 * BLOCK_SIZE);
checkAffinity(blockSize, info, affinity);
// Check outside last range.
affinity = mgr.affinity(info, 18 * BLOCK_SIZE, info.length());
checkAffinity(blockSize, info, affinity);
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridTimeoutProcessorSelfTest method testTimeoutNeverCalledMultithreaded.
/**
* Tests that timeout callback is never called.
*
* @throws Exception If test failed.
*/
public void testTimeoutNeverCalledMultithreaded() throws Exception {
int threads = 20;
final AtomicInteger callCnt = new AtomicInteger(0);
final Collection<GridTimeoutObject> timeObjs = new ConcurrentLinkedQueue<>();
GridTestUtils.runMultiThreaded(new Runnable() {
/** {@inheritDoc} */
@Override
public void run() {
int max = 100;
for (int i = 0; i < max; i++) {
final int idx = i;
GridTimeoutObject obj = new GridTimeoutObject() {
/** Timeout ID. */
private final IgniteUuid id = IgniteUuid.randomUuid();
/** End time. */
private final long endTime = System.currentTimeMillis() + RAND.nextInt(500) + 500;
/** {@inheritDoc} */
@Override
public IgniteUuid timeoutId() {
return id;
}
/** {@inheritDoc} */
@Override
public long endTime() {
return endTime;
}
/** {@inheritDoc} */
@Override
public void onTimeout() {
callCnt.incrementAndGet();
}
/** {@inheritDoc} */
@Override
public String toString() {
return "Timeout test object [idx=" + idx + ", endTime=" + endTime + ", id=" + id + ']';
}
};
timeObjs.add(obj);
ctx.timeout().addTimeoutObject(obj);
}
// (supposing the cycle takes less than 500 ms).
for (GridTimeoutObject obj : timeObjs) {
ctx.timeout().removeTimeoutObject(obj);
}
}
}, threads, "timeout-test-worker");
Thread.sleep(1000);
assert callCnt.get() == 0;
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class KMeansDistributedClusterer method cluster.
/** */
@Override
public KMeansModel cluster(SparseDistributedMatrix points, int k) throws MathIllegalArgumentException, ConvergenceException {
SparseDistributedMatrix pointsCp = (SparseDistributedMatrix) points.like(points.rowSize(), points.columnSize());
// TODO: this copy is very ineffective, just for POC. Immutability of data should be guaranteed by other methods
// such as logical locks for example.
pointsCp.assign(points);
Vector[] centers = initClusterCenters(pointsCp, k);
boolean converged = false;
int iteration = 0;
int dim = pointsCp.viewRow(0).size();
IgniteUuid uid = pointsCp.getUUID();
// Execute iterations of Lloyd's algorithm until converged
while (iteration < maxIterations && !converged) {
SumsAndCounts stats = getSumsAndCounts(centers, dim, uid);
converged = true;
for (Integer ind : stats.sums.keySet()) {
Vector massCenter = stats.sums.get(ind).times(1.0 / stats.counts.get(ind));
if (converged && distance(massCenter, centers[ind]) > epsilon * epsilon)
converged = false;
centers[ind] = massCenter;
}
iteration++;
}
pointsCp.destroy();
return new KMeansModel(centers, getDistanceMeasure());
}
Aggregations