// expected /// <exception cref="System.Exception"/> public virtual void TestSyncFileRange() { FileOutputStream fos = new FileOutputStream(new FilePath(TestDir, "testSyncFileRange" )); try { fos.Write(Runtime.GetBytesForString("foo")); NativeIO.POSIX.Sync_file_range(fos.GetFD(), 0, 1024, NativeIO.POSIX.SyncFileRangeWrite ); } catch (NotSupportedException) { // no way to verify that this actually has synced, // but if it doesn't throw, we can assume it worked // we should just skip the unit test on machines where we don't // have fadvise support Assume.AssumeTrue(false); } finally { fos.Close(); } try { NativeIO.POSIX.Sync_file_range(fos.GetFD(), 0, 1024, NativeIO.POSIX.SyncFileRangeWrite ); NUnit.Framework.Assert.Fail("Did not throw on bad file"); } catch (NativeIOException nioe) { Assert.Equal(Errno.Ebadf, nioe.GetErrno()); } }
/// <exception cref="System.Exception"/> public virtual void TestFstat() { FileOutputStream fos = new FileOutputStream(new FilePath(TestDir, "testfstat")); NativeIO.POSIX.Stat stat = NativeIO.POSIX.GetFstat(fos.GetFD()); fos.Close(); Log.Info("Stat: " + stat.ToString()); string owner = stat.GetOwner(); string expectedOwner = Runtime.GetProperty("user.name"); if (Path.Windows) { UserGroupInformation ugi = UserGroupInformation.CreateRemoteUser(expectedOwner); string adminsGroupString = "Administrators"; if (Arrays.AsList(ugi.GetGroupNames()).Contains(adminsGroupString)) { expectedOwner = adminsGroupString; } } Assert.Equal(expectedOwner, owner); NUnit.Framework.Assert.IsNotNull(stat.GetGroup()); Assert.True(!stat.GetGroup().IsEmpty()); Assert.Equal("Stat mode field should indicate a regular file", NativeIO.POSIX.Stat.SIfreg, stat.GetMode() & NativeIO.POSIX.Stat.SIfmt); }
/// <exception cref="System.Exception"/> public virtual void TestFstatClosedFd() { FileOutputStream fos = new FileOutputStream(new FilePath(TestDir, "testfstat2")); fos.Close(); try { NativeIO.POSIX.Stat stat = NativeIO.POSIX.GetFstat(fos.GetFD()); } catch (NativeIOException nioe) { Log.Info("Got expected exception", nioe); Assert.Equal(Errno.Ebadf, nioe.GetErrno()); } }