Search in sources :

Example 31 with IgfsOutputStream

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

the class IgfsAbstractSelfTest method testCreateDeleteNoClose.

/**
 * Test delete on the file when it was opened for write(create) and is not closed yet.
 *
 * @throws Exception If failed.
 */
public void testCreateDeleteNoClose() throws Exception {
    if (mode != PRIMARY)
        return;
    create(igfs, paths(DIR, SUBDIR), null);
    IgfsOutputStream os = null;
    IgniteUuid id = null;
    try {
        os = igfs.create(FILE, false);
        id = igfs.context().meta().fileId(FILE);
        assert id != null;
        boolean del = igfs.delete(FILE, false);
        assertTrue(del);
        assertFalse(igfs.exists(FILE));
        // The id still exists in meta cache since
        // it is locked for writing and just moved to TRASH.
        // Delete worker cannot delete it for that reason:
        assertTrue(igfs.context().meta().exists(id));
        os.write(chunk);
        os.close();
    } finally {
        U.closeQuiet(os);
    }
    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 32 with IgfsOutputStream

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

the class IgfsAbstractSelfTest method testCreateRenameParentNoClose.

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

Example 33 with IgfsOutputStream

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

the class IgfsAbstractSelfTest method testCreateDeleteParentNoClose.

/**
 * Test delete on the file parent when it was opened for write(create) and is not closed yet.
 *
 * @throws Exception If failed.
 */
public void testCreateDeleteParentNoClose() throws Exception {
    if (mode != PRIMARY)
        return;
    create(igfs, paths(DIR, SUBDIR), null);
    IgfsOutputStream os = null;
    IgniteUuid id = null;
    try {
        os = igfs.create(FILE, false);
        id = igfs.context().meta().fileId(FILE);
        assert id != null;
        boolean del = igfs.delete(SUBDIR, true);
        assertTrue(del);
        assertFalse(igfs.exists(FILE));
        // The id still exists in meta cache since
        // it is locked for writing and just moved to TRASH.
        // Delete worker cannot delete it for that reason:
        assertTrue(igfs.context().meta().exists(id));
        os.write(chunk);
        os.close();
    } finally {
        U.closeQuiet(os);
    }
    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 34 with IgfsOutputStream

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

the class IgfsAbstractSelfTest method testAppend.

/**
 * Test regular append.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TryFinallyCanBeTryWithResources", "EmptyTryBlock" })
public void testAppend() throws Exception {
    if (appendSupported()) {
        create(igfs, paths(DIR, SUBDIR), null);
        assert igfs.exists(SUBDIR);
        createFile(igfs, FILE, true, BLOCK_SIZE, chunk);
        checkFile(igfs, igfsSecondary, FILE, chunk);
        appendFile(igfs, FILE, chunk);
        checkFile(igfs, igfsSecondary, FILE, chunk, chunk);
        // Test create via append:
        IgfsPath path2 = FILE2;
        IgfsOutputStream os = null;
        try {
            os = igfs.append(path2, true);
            writeFileChunks(os, chunk);
        } finally {
            U.closeQuiet(os);
            awaitFileClose(igfs, path2);
        }
        try {
            os = igfs.append(path2, false);
            writeFileChunks(os, chunk);
        } finally {
            U.closeQuiet(os);
            awaitFileClose(igfs, path2);
        }
        checkFile(igfs, igfsSecondary, path2, chunk, chunk);
        // Negative append (create == false):
        try {
            try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/should-not-be-created"), false)) {
            // No-op.
            }
            fail("Exception expected");
        } catch (IgniteException ignored) {
        // okay
        }
        checkNotExist(igfs, igfsSecondary, new IgfsPath("/d1"));
        // Positive mkdirs via append:
        try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/k/l"), true)) {
            checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
            assert igfs.info(new IgfsPath("/k/l")).isFile();
        }
        // Negative append (file is immediate parent):
        try {
            try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/k/l/m"), true)) {
            // No-op.
            }
            fail("Exception expected");
        } catch (IgniteException ignored) {
        // okay
        }
        checkNotExist(igfs, igfsSecondary, new IgfsPath("/k/l/m"));
        checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
        assert igfs.info(new IgfsPath("/k/l")).isFile();
        // Negative append (file is in the parent chain):
        try {
            try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/k/l/m/n/o/p"), true)) {
            // No-op.
            }
            fail("Exception expected");
        } catch (IgniteException ignored) {
        // okay
        }
        checkNotExist(igfs, igfsSecondary, new IgfsPath("/k/l/m"));
        checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
        assert igfs.info(new IgfsPath("/k/l")).isFile();
        // Negative append (target is a directory):
        igfs.mkdirs(new IgfsPath("/x/y"), null);
        checkExist(igfs, igfsSecondary, new IgfsPath("/x/y"));
        assert igfs.info(new IgfsPath("/x/y")).isDirectory();
        try {
            try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y"), true)) {
            // No-op.
            }
            fail("Exception expected");
        } catch (IgniteException ignored) {
        // okay
        }
        // Positive append with create
        try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y/f"), true)) {
            assert igfs.info(new IgfsPath("/x/y/f")).isFile();
        }
        // Positive append with create & 1 mkdirs:
        try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y/z/f"), true)) {
            assert igfs.info(new IgfsPath("/x/y/z/f")).isFile();
        }
        // Positive append with create & 2 mkdirs:
        try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y/z/t/f"), true)) {
            assert igfs.info(new IgfsPath("/x/y/z/t/f")).isFile();
        }
        // Positive mkdirs create & many mkdirs:
        try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y/z/t/t2/t3/t4/t5/f"), true)) {
            assert igfs.info(new IgfsPath("/x/y/z/t/t2/t3/t4/t5/f")).isFile();
        }
        // Negative mkdirs via append (create == false):
        try {
            try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/d1/d2/d3/f"), false)) {
            // No-op.
            }
            fail("Exception expected");
        } catch (IgniteException ignored) {
        // okay
        }
        checkNotExist(igfs, igfsSecondary, new IgfsPath("/d1"));
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteException(org.apache.ignite.IgniteException) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 35 with IgfsOutputStream

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

the class IgfsAbstractSelfTest method testAppendRenameNoClose.

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

Aggregations

IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)47 IgfsPath (org.apache.ignite.igfs.IgfsPath)25 IOException (java.io.IOException)14 IgniteException (org.apache.ignite.IgniteException)13 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