-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Two unit tests are racy because they assume at least 1 ms has elapsed between two calls to stat. This patch has the testing thread sleep for a millisecond to ensure this is true. The patch also alters how the directory listing helper handles invalid situations, with it throwing an exception rather than logging an error. This allows the unit-test that checks this behaviour to do so without logging the error. Target: master Request: 2.10 Request: 2.9 Request: 2.8 Request: 2.7 Request: 2.6 Conflicts: modules/chimera/src/main/java/org/dcache/chimera/DirectoryStreamHelper.java modules/chimera/src/test/java/org/dcache/chimera/DirectoryStreamHelperTest.java
- Loading branch information
1 parent
eef8ed2
commit 91781bf
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
modules/chimera/src/test/java/org/dcache/chimera/DirectoryStreamHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* This library is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Library General Public License as | ||
* published by the Free Software Foundation; either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public | ||
* License along with this program (see the file COPYING.LIB for more | ||
* details); if not, write to the Free Software Foundation, Inc., | ||
* 675 Mass Ave, Cambridge, MA 02139, USA. | ||
*/ | ||
package org.dcache.chimera; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
|
||
import org.dcache.chimera.posix.Stat; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class DirectoryStreamHelperTest { | ||
|
||
@Test(expected=RuntimeException.class) | ||
public void testNegativeNlink() throws ChimeraFsException, IOException { | ||
|
||
FsInode inode = mock(FsInode.class); | ||
Stat stat = mock(Stat.class); | ||
|
||
given(stat.getNlink()).willReturn(-7); | ||
given(inode.stat()).willReturn(stat); | ||
given(inode.statCache()).willReturn(stat); | ||
given(inode.newDirectoryStream()).willReturn( new DirectoryStreamB<HimeraDirectoryEntry>() { | ||
|
||
@Override | ||
public Iterator<HimeraDirectoryEntry> iterator() { | ||
return Collections.emptyIterator(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException {} | ||
}); | ||
DirectoryStreamHelper.listOf(inode); | ||
} | ||
|
||
} |