Committed by
Gerrit Code Review
Clean up tempDir after each test runs.
- Fix for issue with /tmp disk full issue on Jenkins. - Using JUnit Rule TemporaryFolder where possible. Change-Id: Ie91eba37581ba5bf6c32be7f614220e2098ce2f8
Showing
7 changed files
with
59 additions
and
32 deletions
... | @@ -17,9 +17,10 @@ | ... | @@ -17,9 +17,10 @@ |
17 | package org.onosproject.cfg.impl; | 17 | package org.onosproject.cfg.impl; |
18 | 18 | ||
19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
20 | -import com.google.common.io.Files; | ||
21 | import org.junit.Before; | 20 | import org.junit.Before; |
21 | +import org.junit.ClassRule; | ||
22 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | +import org.junit.rules.TemporaryFolder; | ||
23 | import org.onosproject.cfg.ComponentConfigAdapter; | 24 | import org.onosproject.cfg.ComponentConfigAdapter; |
24 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
25 | 26 | ||
... | @@ -38,7 +39,8 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -38,7 +39,8 @@ import static org.slf4j.LoggerFactory.getLogger; |
38 | */ | 39 | */ |
39 | public class ComponentConfigLoaderTest { | 40 | public class ComponentConfigLoaderTest { |
40 | 41 | ||
41 | - static final File TEST_DIR = Files.createTempDir(); | 42 | + @ClassRule |
43 | + public static TemporaryFolder testFolder = new TemporaryFolder(); | ||
42 | 44 | ||
43 | private static final String FOO_COMPONENT = "fooComponent"; | 45 | private static final String FOO_COMPONENT = "fooComponent"; |
44 | 46 | ||
... | @@ -53,8 +55,8 @@ public class ComponentConfigLoaderTest { | ... | @@ -53,8 +55,8 @@ public class ComponentConfigLoaderTest { |
53 | * and assign it to the loader.configService for the test. | 55 | * and assign it to the loader.configService for the test. |
54 | */ | 56 | */ |
55 | @Before | 57 | @Before |
56 | - public void setUp() { | 58 | + public void setUp() throws IOException { |
57 | - ComponentConfigLoader.cfgFile = new File(TEST_DIR, "test.json"); | 59 | + ComponentConfigLoader.cfgFile = new File(testFolder.newFolder(), "test.json"); |
58 | loader = new ComponentConfigLoader(); | 60 | loader = new ComponentConfigLoader(); |
59 | service = new TestConfigService(); | 61 | service = new TestConfigService(); |
60 | loader.configService = service; | 62 | loader.configService = service; | ... | ... |
... | @@ -23,7 +23,9 @@ import java.util.Map; | ... | @@ -23,7 +23,9 @@ import java.util.Map; |
23 | import java.util.stream.IntStream; | 23 | import java.util.stream.IntStream; |
24 | 24 | ||
25 | import org.junit.Before; | 25 | import org.junit.Before; |
26 | +import org.junit.ClassRule; | ||
26 | import org.junit.Test; | 27 | import org.junit.Test; |
28 | +import org.junit.rules.TemporaryFolder; | ||
27 | import org.onlab.junit.TestTools; | 29 | import org.onlab.junit.TestTools; |
28 | import org.onlab.util.ItemNotFoundException; | 30 | import org.onlab.util.ItemNotFoundException; |
29 | import org.onosproject.net.DeviceId; | 31 | import org.onosproject.net.DeviceId; |
... | @@ -36,8 +38,6 @@ import org.projectfloodlight.openflow.protocol.OFDescStatsReply; | ... | @@ -36,8 +38,6 @@ import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
36 | import org.slf4j.Logger; | 38 | import org.slf4j.Logger; |
37 | import org.slf4j.LoggerFactory; | 39 | import org.slf4j.LoggerFactory; |
38 | 40 | ||
39 | -import com.google.common.io.Files; | ||
40 | - | ||
41 | import static com.google.common.io.ByteStreams.toByteArray; | 41 | import static com.google.common.io.ByteStreams.toByteArray; |
42 | import static com.google.common.io.Files.write; | 42 | import static com.google.common.io.Files.write; |
43 | import static org.hamcrest.MatcherAssert.assertThat; | 43 | import static org.hamcrest.MatcherAssert.assertThat; |
... | @@ -53,16 +53,17 @@ import static org.hamcrest.Matchers.nullValue; | ... | @@ -53,16 +53,17 @@ import static org.hamcrest.Matchers.nullValue; |
53 | */ | 53 | */ |
54 | public class ControllerTest { | 54 | public class ControllerTest { |
55 | 55 | ||
56 | + @ClassRule | ||
57 | + public static TemporaryFolder testFolder = new TemporaryFolder(); | ||
58 | + | ||
56 | Controller controller; | 59 | Controller controller; |
57 | protected static final Logger log = LoggerFactory.getLogger(ControllerTest.class); | 60 | protected static final Logger log = LoggerFactory.getLogger(ControllerTest.class); |
58 | 61 | ||
59 | - static final File TEST_DIR = Files.createTempDir(); | ||
60 | - | ||
61 | /* | 62 | /* |
62 | * Writes the necessary file for the tests in the temporary directory | 63 | * Writes the necessary file for the tests in the temporary directory |
63 | */ | 64 | */ |
64 | - static File stageTestResource(String name) throws IOException { | 65 | + private static File stageTestResource(String name) throws IOException { |
65 | - File file = new File(TEST_DIR, name); | 66 | + File file = new File(testFolder.newFolder(), name); |
66 | byte[] bytes = toByteArray(ControllerTest.class.getResourceAsStream(name)); | 67 | byte[] bytes = toByteArray(ControllerTest.class.getResourceAsStream(name)); |
67 | write(bytes, file); | 68 | write(bytes, file); |
68 | return file; | 69 | return file; | ... | ... |
... | @@ -15,9 +15,12 @@ | ... | @@ -15,9 +15,12 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.stc; | 16 | package org.onlab.stc; |
17 | 17 | ||
18 | -import com.google.common.io.Files; | 18 | +import org.junit.AfterClass; |
19 | import org.junit.BeforeClass; | 19 | import org.junit.BeforeClass; |
20 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | +import org.onlab.util.Tools; | ||
22 | + | ||
23 | +import com.google.common.io.Files; | ||
21 | 24 | ||
22 | import java.io.File; | 25 | import java.io.File; |
23 | import java.io.FileInputStream; | 26 | import java.io.FileInputStream; |
... | @@ -35,10 +38,12 @@ import static org.onlab.stc.Scenario.loadScenario; | ... | @@ -35,10 +38,12 @@ import static org.onlab.stc.Scenario.loadScenario; |
35 | */ | 38 | */ |
36 | public class CompilerTest { | 39 | public class CompilerTest { |
37 | 40 | ||
38 | - static final File TEST_DIR = Files.createTempDir(); | 41 | + |
42 | + private static File testDir; | ||
39 | 43 | ||
40 | @BeforeClass | 44 | @BeforeClass |
41 | public static void setUpClass() throws IOException { | 45 | public static void setUpClass() throws IOException { |
46 | + testDir = Files.createTempDir(); | ||
42 | stageTestResource("scenario.xml"); | 47 | stageTestResource("scenario.xml"); |
43 | stageTestResource("simple-scenario.xml"); | 48 | stageTestResource("simple-scenario.xml"); |
44 | stageTestResource("one-scenario.xml"); | 49 | stageTestResource("one-scenario.xml"); |
... | @@ -49,16 +54,21 @@ public class CompilerTest { | ... | @@ -49,16 +54,21 @@ public class CompilerTest { |
49 | System.setProperty("TOC1", "1.2.3.1"); | 54 | System.setProperty("TOC1", "1.2.3.1"); |
50 | System.setProperty("TOC2", "1.2.3.2"); | 55 | System.setProperty("TOC2", "1.2.3.2"); |
51 | System.setProperty("TOC3", "1.2.3.3"); | 56 | System.setProperty("TOC3", "1.2.3.3"); |
52 | - System.setProperty("test.dir", TEST_DIR.getAbsolutePath()); | 57 | + System.setProperty("test.dir", testDir.getAbsolutePath()); |
58 | + } | ||
59 | + | ||
60 | + @AfterClass | ||
61 | + public static void tearDownClass() throws IOException { | ||
62 | + Tools.removeDirectory(testDir.getPath()); | ||
53 | } | 63 | } |
54 | 64 | ||
55 | static FileInputStream getStream(String name) throws FileNotFoundException { | 65 | static FileInputStream getStream(String name) throws FileNotFoundException { |
56 | - return new FileInputStream(new File(TEST_DIR, name)); | 66 | + return new FileInputStream(new File(testDir, name)); |
57 | } | 67 | } |
58 | 68 | ||
59 | static void stageTestResource(String name) throws IOException { | 69 | static void stageTestResource(String name) throws IOException { |
60 | byte[] bytes = toByteArray(CompilerTest.class.getResourceAsStream(name)); | 70 | byte[] bytes = toByteArray(CompilerTest.class.getResourceAsStream(name)); |
61 | - write(bytes, new File(TEST_DIR, name)); | 71 | + write(bytes, new File(testDir, name)); |
62 | } | 72 | } |
63 | 73 | ||
64 | @Test | 74 | @Test |
... | @@ -72,7 +82,7 @@ public class CompilerTest { | ... | @@ -72,7 +82,7 @@ public class CompilerTest { |
72 | assertEquals("incorrect step count", 33, flow.getVertexes().size()); | 82 | assertEquals("incorrect step count", 33, flow.getVertexes().size()); |
73 | assertEquals("incorrect dependency count", 26, flow.getEdges().size()); | 83 | assertEquals("incorrect dependency count", 26, flow.getEdges().size()); |
74 | assertEquals("incorrect logDir", | 84 | assertEquals("incorrect logDir", |
75 | - new File(TEST_DIR.getAbsolutePath(), "foo"), compiler.logDir()); | 85 | + new File(testDir.getAbsolutePath(), "foo"), compiler.logDir()); |
76 | 86 | ||
77 | Step step = compiler.getStep("there"); | 87 | Step step = compiler.getStep("there"); |
78 | assertEquals("incorrect edge count", 2, flow.getEdgesFrom(step).size()); | 88 | assertEquals("incorrect edge count", 2, flow.getEdgesFrom(step).size()); | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.stc; | 16 | package org.onlab.stc; |
17 | 17 | ||
18 | +import org.junit.AfterClass; | ||
18 | import org.junit.BeforeClass; | 19 | import org.junit.BeforeClass; |
19 | import org.junit.Test; | 20 | import org.junit.Test; |
20 | import org.onlab.util.Tools; | 21 | import org.onlab.util.Tools; |
... | @@ -36,11 +37,15 @@ public class CoordinatorTest { | ... | @@ -36,11 +37,15 @@ public class CoordinatorTest { |
36 | @BeforeClass | 37 | @BeforeClass |
37 | public static void setUpClass() throws IOException { | 38 | public static void setUpClass() throws IOException { |
38 | CompilerTest.setUpClass(); | 39 | CompilerTest.setUpClass(); |
39 | - Tools.removeDirectory(StepProcessorTest.DIR); | ||
40 | 40 | ||
41 | StepProcessor.launcher = "true "; | 41 | StepProcessor.launcher = "true "; |
42 | } | 42 | } |
43 | 43 | ||
44 | + @AfterClass | ||
45 | + public static void tearDownClass() throws IOException { | ||
46 | + CompilerTest.tearDownClass(); | ||
47 | + } | ||
48 | + | ||
44 | @Test | 49 | @Test |
45 | public void simple() throws IOException, InterruptedException { | 50 | public void simple() throws IOException, InterruptedException { |
46 | executeTest("simple-scenario.xml"); | 51 | executeTest("simple-scenario.xml"); | ... | ... |
... | @@ -29,6 +29,7 @@ public class DependencyTest extends StepTest { | ... | @@ -29,6 +29,7 @@ public class DependencyTest extends StepTest { |
29 | 29 | ||
30 | protected Step step1, step2; | 30 | protected Step step1, step2; |
31 | 31 | ||
32 | + @Override | ||
32 | @Before | 33 | @Before |
33 | public void setUp() throws ConfigurationException { | 34 | public void setUp() throws ConfigurationException { |
34 | super.setUp(); | 35 | super.setUp(); |
... | @@ -52,6 +53,7 @@ public class DependencyTest extends StepTest { | ... | @@ -52,6 +53,7 @@ public class DependencyTest extends StepTest { |
52 | assertTrue("incorrect isSoft", soft.isSoft()); | 53 | assertTrue("incorrect isSoft", soft.isSoft()); |
53 | } | 54 | } |
54 | 55 | ||
56 | + @Override | ||
55 | @Test | 57 | @Test |
56 | public void equality() { | 58 | public void equality() { |
57 | Dependency d1 = new Dependency(step1, step2, false); | 59 | Dependency d1 = new Dependency(step1, step2, false); | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.stc; | 16 | package org.onlab.stc; |
17 | 17 | ||
18 | +import org.junit.AfterClass; | ||
19 | +import org.junit.BeforeClass; | ||
18 | import org.junit.Test; | 20 | import org.junit.Test; |
19 | import org.onlab.stc.MonitorLayout.Box; | 21 | import org.onlab.stc.MonitorLayout.Box; |
20 | 22 | ||
... | @@ -33,6 +35,16 @@ public class MonitorLayoutTest { | ... | @@ -33,6 +35,16 @@ public class MonitorLayoutTest { |
33 | 35 | ||
34 | private MonitorLayout layout; | 36 | private MonitorLayout layout; |
35 | 37 | ||
38 | + @BeforeClass | ||
39 | + public static void setUpClass() throws IOException { | ||
40 | + CompilerTest.setUpClass(); | ||
41 | + } | ||
42 | + | ||
43 | + @AfterClass | ||
44 | + public static void tearDownClass() throws IOException { | ||
45 | + CompilerTest.tearDownClass(); | ||
46 | + } | ||
47 | + | ||
36 | private Compiler getCompiler(String name) throws IOException { | 48 | private Compiler getCompiler(String name) throws IOException { |
37 | stageTestResource(name); | 49 | stageTestResource(name); |
38 | Scenario scenario = loadScenario(getStream(name)); | 50 | Scenario scenario = loadScenario(getStream(name)); | ... | ... |
... | @@ -15,15 +15,11 @@ | ... | @@ -15,15 +15,11 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.stc; | 16 | package org.onlab.stc; |
17 | 17 | ||
18 | -import com.google.common.io.Files; | ||
19 | -import org.junit.AfterClass; | ||
20 | import org.junit.BeforeClass; | 18 | import org.junit.BeforeClass; |
19 | +import org.junit.ClassRule; | ||
21 | import org.junit.Test; | 20 | import org.junit.Test; |
22 | -import org.onlab.util.Tools; | 21 | +import org.junit.rules.TemporaryFolder; |
23 | - | ||
24 | import java.io.File; | 22 | import java.io.File; |
25 | -import java.io.IOException; | ||
26 | - | ||
27 | import static com.google.common.base.Preconditions.checkState; | 23 | import static com.google.common.base.Preconditions.checkState; |
28 | import static org.junit.Assert.assertEquals; | 24 | import static org.junit.Assert.assertEquals; |
29 | import static org.junit.Assert.assertTrue; | 25 | import static org.junit.Assert.assertTrue; |
... | @@ -34,24 +30,23 @@ import static org.onlab.stc.Coordinator.Status.SUCCEEDED; | ... | @@ -34,24 +30,23 @@ import static org.onlab.stc.Coordinator.Status.SUCCEEDED; |
34 | */ | 30 | */ |
35 | public class StepProcessorTest { | 31 | public class StepProcessorTest { |
36 | 32 | ||
37 | - static final File DIR = Files.createTempDir(); | 33 | + @ClassRule |
34 | + public static TemporaryFolder testFolder = new TemporaryFolder(); | ||
35 | + | ||
36 | + private static File dir; | ||
38 | private final Listener delegate = new Listener(); | 37 | private final Listener delegate = new Listener(); |
39 | 38 | ||
40 | @BeforeClass | 39 | @BeforeClass |
41 | public static void setUpClass() { | 40 | public static void setUpClass() { |
41 | + dir = testFolder.getRoot(); | ||
42 | StepProcessor.launcher = "echo"; | 42 | StepProcessor.launcher = "echo"; |
43 | - checkState(DIR.exists() || DIR.mkdirs(), "Unable to create directory"); | 43 | + checkState(dir.exists() || dir.mkdirs(), "Unable to create directory"); |
44 | - } | ||
45 | - | ||
46 | - @AfterClass | ||
47 | - public static void tearDownClass() throws IOException { | ||
48 | - Tools.removeDirectory(DIR.getPath()); | ||
49 | } | 44 | } |
50 | 45 | ||
51 | @Test | 46 | @Test |
52 | public void basics() { | 47 | public void basics() { |
53 | - Step step = new Step("foo", "ls " + DIR.getAbsolutePath(), null, null, null, 0); | 48 | + Step step = new Step("foo", "ls " + dir.getAbsolutePath(), null, null, null, 0); |
54 | - StepProcessor processor = new StepProcessor(step, DIR, delegate, step.command()); | 49 | + StepProcessor processor = new StepProcessor(step, dir, delegate, step.command()); |
55 | processor.run(); | 50 | processor.run(); |
56 | assertTrue("should be started", delegate.started); | 51 | assertTrue("should be started", delegate.started); |
57 | assertTrue("should be stopped", delegate.stopped); | 52 | assertTrue("should be stopped", delegate.stopped); | ... | ... |
-
Please register or login to post a comment