Search in sources :

Example 1 with Writer

use of com.android.internal.util.FileRotator.Writer in project platform_frameworks_base by android.

the class FileRotatorTest method testThrowRestoresBackup.

public void testThrowRestoresBackup() throws Exception {
    final FileRotator rotate = new FileRotator(mBasePath, PREFIX, MINUTE_IN_MILLIS, DAY_IN_MILLIS);
    final RecordingReader reader = new RecordingReader();
    long currentTime = TEST_TIME;
    // first, write some valid data
    rotate.combineActive(reader, writer("foo"), currentTime);
    reader.assertRead();
    assertReadAll(rotate, "foo");
    try {
        // now, try writing which will throw
        reader.reset();
        rotate.combineActive(reader, new Writer() {

            public void write(OutputStream out) throws IOException {
                new DataOutputStream(out).writeUTF("bar");
                throw new NullPointerException("yikes");
            }
        }, currentTime);
        fail("woah, somehow able to write exception");
    } catch (IOException e) {
    // expected from above
    }
    // assert that we read original data, and that it's still intact after
    // the failed write above.
    reader.assertRead("foo");
    assertReadAll(rotate, "foo");
}
Also used : DataOutputStream(java.io.DataOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Writer(com.android.internal.util.FileRotator.Writer)

Example 2 with Writer

use of com.android.internal.util.FileRotator.Writer in project android_frameworks_base by ParanoidAndroid.

the class FileRotatorTest method testThrowRestoresBackup.

public void testThrowRestoresBackup() throws Exception {
    final FileRotator rotate = new FileRotator(mBasePath, PREFIX, MINUTE_IN_MILLIS, DAY_IN_MILLIS);
    final RecordingReader reader = new RecordingReader();
    long currentTime = TEST_TIME;
    // first, write some valid data
    rotate.combineActive(reader, writer("foo"), currentTime);
    reader.assertRead();
    assertReadAll(rotate, "foo");
    try {
        // now, try writing which will throw
        reader.reset();
        rotate.combineActive(reader, new Writer() {

            public void write(OutputStream out) throws IOException {
                new DataOutputStream(out).writeUTF("bar");
                throw new NullPointerException("yikes");
            }
        }, currentTime);
        fail("woah, somehow able to write exception");
    } catch (IOException e) {
    // expected from above
    }
    // assert that we read original data, and that it's still intact after
    // the failed write above.
    reader.assertRead("foo");
    assertReadAll(rotate, "foo");
}
Also used : DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) DataOutputStream(java.io.DataOutputStream) IOException(java.io.IOException) Writer(com.android.internal.util.FileRotator.Writer)

Example 3 with Writer

use of com.android.internal.util.FileRotator.Writer in project android_frameworks_base by DirtyUnicorns.

the class FileRotatorTest method testThrowRestoresBackup.

public void testThrowRestoresBackup() throws Exception {
    final FileRotator rotate = new FileRotator(mBasePath, PREFIX, MINUTE_IN_MILLIS, DAY_IN_MILLIS);
    final RecordingReader reader = new RecordingReader();
    long currentTime = TEST_TIME;
    // first, write some valid data
    rotate.combineActive(reader, writer("foo"), currentTime);
    reader.assertRead();
    assertReadAll(rotate, "foo");
    try {
        // now, try writing which will throw
        reader.reset();
        rotate.combineActive(reader, new Writer() {

            public void write(OutputStream out) throws IOException {
                new DataOutputStream(out).writeUTF("bar");
                throw new NullPointerException("yikes");
            }
        }, currentTime);
        fail("woah, somehow able to write exception");
    } catch (IOException e) {
    // expected from above
    }
    // assert that we read original data, and that it's still intact after
    // the failed write above.
    reader.assertRead("foo");
    assertReadAll(rotate, "foo");
}
Also used : DataOutputStream(java.io.DataOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Writer(com.android.internal.util.FileRotator.Writer)

Example 4 with Writer

use of com.android.internal.util.FileRotator.Writer in project android_frameworks_base by AOSPA.

the class FileRotatorTest method testThrowRestoresBackup.

public void testThrowRestoresBackup() throws Exception {
    final FileRotator rotate = new FileRotator(mBasePath, PREFIX, MINUTE_IN_MILLIS, DAY_IN_MILLIS);
    final RecordingReader reader = new RecordingReader();
    long currentTime = TEST_TIME;
    // first, write some valid data
    rotate.combineActive(reader, writer("foo"), currentTime);
    reader.assertRead();
    assertReadAll(rotate, "foo");
    try {
        // now, try writing which will throw
        reader.reset();
        rotate.combineActive(reader, new Writer() {

            public void write(OutputStream out) throws IOException {
                new DataOutputStream(out).writeUTF("bar");
                throw new NullPointerException("yikes");
            }
        }, currentTime);
        fail("woah, somehow able to write exception");
    } catch (IOException e) {
    // expected from above
    }
    // assert that we read original data, and that it's still intact after
    // the failed write above.
    reader.assertRead("foo");
    assertReadAll(rotate, "foo");
}
Also used : DataOutputStream(java.io.DataOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Writer(com.android.internal.util.FileRotator.Writer)

Example 5 with Writer

use of com.android.internal.util.FileRotator.Writer in project android_frameworks_base by ResurrectionRemix.

the class FileRotatorTest method testThrowRestoresBackup.

public void testThrowRestoresBackup() throws Exception {
    final FileRotator rotate = new FileRotator(mBasePath, PREFIX, MINUTE_IN_MILLIS, DAY_IN_MILLIS);
    final RecordingReader reader = new RecordingReader();
    long currentTime = TEST_TIME;
    // first, write some valid data
    rotate.combineActive(reader, writer("foo"), currentTime);
    reader.assertRead();
    assertReadAll(rotate, "foo");
    try {
        // now, try writing which will throw
        reader.reset();
        rotate.combineActive(reader, new Writer() {

            public void write(OutputStream out) throws IOException {
                new DataOutputStream(out).writeUTF("bar");
                throw new NullPointerException("yikes");
            }
        }, currentTime);
        fail("woah, somehow able to write exception");
    } catch (IOException e) {
    // expected from above
    }
    // assert that we read original data, and that it's still intact after
    // the failed write above.
    reader.assertRead("foo");
    assertReadAll(rotate, "foo");
}
Also used : DataOutputStream(java.io.DataOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Writer(com.android.internal.util.FileRotator.Writer)

Aggregations

Writer (com.android.internal.util.FileRotator.Writer)6 DataOutputStream (java.io.DataOutputStream)6 FileOutputStream (java.io.FileOutputStream)6 IOException (java.io.IOException)6 OutputStream (java.io.OutputStream)6