Search in sources :

Example 6 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.

the class IgfsAbstractSelfTest method testCreateConsistency.

/**
     * Ensure consistency of data during file creation.
     *
     * @throws Exception If failed.
     */
public void testCreateConsistency() throws Exception {
    final AtomicInteger ctr = new AtomicInteger();
    final AtomicReference<Exception> err = new AtomicReference<>();
    final int threadCnt = 10;
    multithreaded(new Runnable() {

        @Override
        public void run() {
            int idx = ctr.incrementAndGet();
            final IgfsPath path = new IgfsPath("/file" + idx);
            try {
                for (int i = 0; i < REPEAT_CNT; i++) {
                    IgfsOutputStream os = igfs.create(path, 128, true, /*overwrite*/
                    null, 0, 256, null);
                    os.write(chunk);
                    os.close();
                    assert igfs.exists(path);
                }
                awaitFileClose(igfs, path);
                checkFileContent(igfs, path, chunk);
            } catch (IOException | IgniteCheckedException e) {
                // Log the very first error.
                err.compareAndSet(null, e);
            }
        }
    }, threadCnt);
    if (err.get() != null)
        throw err.get();
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream) IgfsParentNotDirectoryException(org.apache.ignite.igfs.IgfsParentNotDirectoryException) IgfsDirectoryNotEmptyException(org.apache.ignite.igfs.IgfsDirectoryNotEmptyException) IgfsException(org.apache.ignite.igfs.IgfsException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException)

Example 7 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.

the class IgfsAbstractSelfTest method testCreateRenameNoClose.

/**
     * Test rename on the file when it was opened for write(create) and is not closed yet.
     *
     * @throws Exception If failed.
     */
public void testCreateRenameNoClose() throws Exception {
    if (dual)
        return;
    create(igfs, paths(DIR, SUBDIR), null);
    IgfsOutputStream os = null;
    try {
        os = igfs.create(FILE, true);
        igfs.rename(FILE, FILE2);
        os.close();
    } finally {
        U.closeQuiet(os);
    }
}
Also used : IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 8 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.

the class IgfsAbstractSelfTest method testStop.

/**
     * Ensure that IGFS is able to stop in case not closed output stream exist.
     *
     * @throws Exception If failed.
     */
public void testStop() throws Exception {
    create(igfs, paths(DIR, SUBDIR), null);
    IgfsOutputStream os = igfs.create(FILE, true);
    os.write(chunk);
    igfs.stop(true);
    // Reset test state.
    afterTestsStopped();
    beforeTestsStarted();
}
Also used : IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 9 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.

the class IgfsAbstractSelfTest method testAppendUpdateNoClose.

/**
     * Test update on the file when it was opened for write(create) and is not closed yet.
     *
     * @throws Exception If failed.
     */
public void testAppendUpdateNoClose() throws Exception {
    if (dual)
        return;
    if (appendSupported()) {
        Map<String, String> props = properties("owner", "group", "0555");
        create(igfs, paths(DIR, SUBDIR), null);
        createFile(igfs, FILE, false);
        IgfsOutputStream os = null;
        try {
            os = igfs.append(FILE, false);
            if (permissionsSupported())
                igfs.update(FILE, props);
            os.close();
        } finally {
            U.closeQuiet(os);
        }
    }
}
Also used : IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 10 with IgfsOutputStream

use of org.apache.ignite.igfs.IgfsOutputStream 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)

Aggregations

IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)46 IgfsPath (org.apache.ignite.igfs.IgfsPath)24 IOException (java.io.IOException)13 IgniteException (org.apache.ignite.IgniteException)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)8 IgniteUuid (org.apache.ignite.lang.IgniteUuid)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 IgniteFileSystem (org.apache.ignite.IgniteFileSystem)4 IgfsDirectoryNotEmptyException (org.apache.ignite.igfs.IgfsDirectoryNotEmptyException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IgfsException (org.apache.ignite.igfs.IgfsException)3 IgfsMetrics (org.apache.ignite.igfs.IgfsMetrics)3 IgfsParentNotDirectoryException (org.apache.ignite.igfs.IgfsParentNotDirectoryException)3 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2