@Test public void testDoubleOpenWriteFailure() throws Exception { log.info("testDoubleOpenWriteFailure1"); // what we do here is to make sure that if we're // unable to roll files, by forcing path in TestTextFileWriter, // we wont get error from hadoop which would look like // java.io.FileNotFoundException: ID mismatch. Request id and saved id: 16399 , 16400 // which happens if two writers use same file at a same time // and file is opened in overwrite mode. String[] dataArray = new String[] {DATA10}; TestTextFileWriter writer1 = new TestTextFileWriter(getConfiguration(), testDefaultPath, null); writer1.setMaxOpenAttempts(1); writer1.setFileNamingStrategy(new RollingFileNamingStrategy()); TestTextFileWriter writer2 = new TestTextFileWriter(getConfiguration(), testDefaultPath, null); writer2.setFileNamingStrategy(new RollingFileNamingStrategy()); writer2.setMaxOpenAttempts(1); Exception catched = null; try { TestUtils.writeData(writer1, dataArray, false); TestUtils.writeData(writer2, dataArray, false); } catch (Exception e) { catched = e; } TestUtils.close(writer1); TestUtils.close(writer2); assertThat(catched, instanceOf(StoreException.class)); assertThat(catched.getMessage(), containsString("We've reached")); }
@Test public void testDoubleOpenWriteFailureShouldNotHappen() throws Exception { // mostly similar that testDoubleOpenWriteFailure() but // we don't force the path so rollover should work String[] dataArray = new String[] {DATA10}; TextFileWriter writer1 = new TextFileWriter(getConfiguration(), testDefaultPath, null); writer1.setFileNamingStrategy(new RollingFileNamingStrategy()); TextFileWriter writer2 = new TextFileWriter(getConfiguration(), testDefaultPath, null); writer2.setFileNamingStrategy(new RollingFileNamingStrategy()); TestUtils.writeData(writer1, dataArray, false); TestUtils.writeData(writer2, dataArray, false); TestUtils.close(writer1); TestUtils.close(writer2); // we're ok if we don't get exceptions }