Search in sources :

Example 31 with IgniteUuid

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));
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) Event(org.apache.ignite.events.Event) TaskEvent(org.apache.ignite.events.TaskEvent) Ignite(org.apache.ignite.Ignite)

Example 32 with IgniteUuid

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);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 33 with IgniteUuid

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);
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsBlockLocation(org.apache.ignite.igfs.IgfsBlockLocation)

Example 34 with IgniteUuid

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 35 with IgniteUuid

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());
}
Also used : SparseDistributedMatrix(org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix) IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Aggregations

IgniteUuid (org.apache.ignite.lang.IgniteUuid)98 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)22 UUID (java.util.UUID)19 IgniteException (org.apache.ignite.IgniteException)17 HashMap (java.util.HashMap)13 Map (java.util.Map)11 IgfsPath (org.apache.ignite.igfs.IgfsPath)11 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)10 ArrayList (java.util.ArrayList)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 Nullable (org.jetbrains.annotations.Nullable)9 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)7 TreeSet (java.util.TreeSet)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 IgfsException (org.apache.ignite.igfs.IgfsException)6 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Event (org.apache.ignite.events.Event)5 TaskEvent (org.apache.ignite.events.TaskEvent)5 IgfsPathIsDirectoryException (org.apache.ignite.igfs.IgfsPathIsDirectoryException)5