private static TConfig push(Map<String, ?> env) { final TArchiveDetector detector = (TArchiveDetector) env.get( Parameter.ARCHIVE_DETECTOR); final TConfig config = TConfig.push(); if (null != detector) config.setArchiveDetector(detector); return config; }
if (!isArchive()) return this; final TConfig config = TConfig.push(); try { config.setArchiveDetector(TArchiveDetector.NULL);
throw new IllegalUsageException(); final TConfig config = TConfig.push(); try { config.setOutputPreferences(config.getOutputPreferences()
@edu.umd.cs.findbugs.annotations.SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") private void assertCreateNewEnhancedFile() throws IOException { final File file1 = new TFile(archive, "test.txt"); final File file2 = new TFile(file1, "test.txt"); TConfig config = TConfig.push(); try { config.setLenient(false); try { file1.createNewFile(); fail("Creating a file in a non-existent directory should throw an IOException!"); } catch (IOException expected) { } assertCreateNewFile(archive, file1, file2); } finally { config.close(); } assertCreateNewFile(archive, file1, file2); }
@edu.umd.cs.findbugs.annotations.SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") private void assertCreateNewEnhancedFile() throws IOException { final TPath file1 = archive.resolve("test.txt"); final TPath file2 = file1.resolve("test.txt"); TConfig config = TConfig.push(); try { config.setLenient(false); try { createFile(file1); fail("Creating a file in a non-existent directory should throw an IOException!"); } catch (IOException expected) { } assertCreateNewFile(archive, file1, file2); } finally { config.close(); } assertCreateNewFile(archive, file1, file2); }
@Test public final void testStrictFileOutputStream() throws IOException { TPath file = archive.resolve("test.txt"); TConfig config = TConfig.push(); try { config.setLenient(false); try { assertFileOutputStream(file); fail("Creating ghost directories should not be allowed when Path.isLenient() is false!"); } catch (IOException expected) { } createDirectory(archive); assertFileOutputStream(file); delete(archive); } finally { config.close(); } }
delete(dir1); final TConfig config = TConfig.push(); try { config.setLenient(false);
@Test public void pop() { TConfig.push(); TConfig.pop(); try { TConfig.pop(); fail(); } catch (IllegalStateException emptyStack) { assertTrue(emptyStack.getCause() instanceof NoSuchElementException); } }
@Test public void close() { final TConfig c1 = TConfig.push(); try { final TConfig c2 = TConfig.push(); try { c1.close(); fail(); } catch (IllegalStateException notTopElement) { assertSame(c2, TConfig.get()); } finally { c2.close(); } c2.close(); // should get ignored assertSame(c1, TConfig.get()); } finally { c1.close(); } c1.close(); // should get ignored }
@Override public void setUp() throws IOException { super.setUp(); detector = new TArchiveDetector(getSuffixList(), getArchiveDriver()); environment = Collections.singletonMap(ARCHIVE_DETECTOR, detector); final TConfig config = TConfig.push(); // Using a private file system manager would normally violate the third // party access constraints, but in this context it's safe because no // two test methods should ever access the same archive file(s) except // when performing a sync of all mounted file systems. // Mind that a sync should always succeed (unless there's an issue in // the parent file system) und must not confuse other threads about the // state of the synced archive file(s). // So the default value 'false' helps to identify potential isolation // issues in case this invariant is not met. // See http://truezip.java.net/truezip-file/usage.html#Third_Party_Access if (ISOLATE_FS_MANAGER) config.setFsManager(new FsDefaultManager()); config.setLenient(true); config.setArchiveDetector(detector); }
final TConfig config = TConfig.push(); try {
@Test public final void testStrictFileOutputStream() throws IOException { TFile file = new TFile(archive, "test.txt"); TConfig config = TConfig.push(); try { config.setLenient(false); try { assertFileOutputStream(file); fail("Creating ghost directories should not be allowed when File.isLenient() is false!"); } catch (FileNotFoundException expected) { } assertTrue(archive.mkdir()); assertFileOutputStream(file); archive.rm(); } finally { config.close(); } }
@Test public void testConfiguration() { // Create reference to the current directory. TPath directory = new TPath(""); // This is how you would detect a prospective archive file. TPath archive = directory.resolve("archive.mok"); TPath file; TConfig config = TConfig.push(); try { config.setArchiveDetector(TArchiveDetector.NULL); // Ignore prospective archive file here. file = directory.resolve("archive.mok"); } finally { config.close(); } // Once created, the prospective archive file detection does not change // because a TPath is immutable. assert archive.getArchiveDetector() == getArchiveDetector(); assert archive.isArchive(); assert file.getArchiveDetector() == TArchiveDetector.NULL; assert !file.isArchive(); } }
@Test public void standardUseCase() { TFile f1 = new TFile("file.mok"); assertFalse(f1.isArchive()); // Push a new current configuration on the thread local stack. TConfig c = TConfig.push(); try { // Change the inheritable thread local configuration. c.setArchiveDetector( new TArchiveDetector("mok", new MockArchiveDriver())); // Use the inheritable thread local configuration. TFile f2 = new TFile("file.mok"); assertTrue(f2.isArchive()); // Do some I/O here. } finally { // Pop the configuration off the inheritable thread local stack. c.close(); } }
assertThat(c1.getArchiveDetector(), sameInstance(ad1)); final TArchiveDetector ad2 = new TArchiveDetector("mok", d); final TConfig c2 = TConfig.push(); try { c2.setArchiveDetector(ad2); assertThat(c2.getArchiveDetector(), sameInstance(ad2)); final TArchiveDetector ad3 = new TArchiveDetector("mok", d); final TConfig c3 = TConfig.push(); try { c3.setArchiveDetector(ad3);
@Test public void preferences() { final TConfig c = TConfig.push(); try { assertTrue(c.isLenient());
dir1.rm(); final TConfig config = TConfig.push(); try { config.setLenient(false);