File tree 5 files changed +27
-32
lines changed
part1.2-from-sequential-to-parallel/src
5 files changed +27
-32
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,13 @@ class FileService {
5
5
static void setText (File parent , String name , String text ) {
6
6
MetricService . incrementInvocationsCount()
7
7
new File (parent, name). text = text
8
+ sleep text. length() * 20
8
9
}
9
10
10
11
static void appendText (File parent , String name , String text ) {
11
12
MetricService . incrementInvocationsCount()
12
13
new File (parent, name). append(text)
14
+ sleep text. length() * 10
13
15
}
14
16
15
17
}
Original file line number Diff line number Diff line change @@ -2,28 +2,26 @@ package migration
2
2
3
3
class AppendTextSpec extends BaseSpec {
4
4
5
- def " append text" () {
6
- given :
7
- def name = " test"
5
+ def fileName = " test"
6
+
7
+ def setup () {
8
+ new File (rootDir, fileName). text = " initial text"
9
+ }
8
10
11
+ def " append text" () {
9
12
when :
10
- FileService . appendText(tempDir, name, " some text" )
11
- sleep 100
13
+ FileService . appendText(rootDir, fileName, " additional text" )
12
14
13
15
then :
14
- new File (tempDir, name ). text == ' some text'
16
+ new File (rootDir, fileName ). text == ' initial textadditional text'
15
17
}
16
18
17
19
def " append empty text" () {
18
- given :
19
- def name = " test"
20
-
21
20
when :
22
- FileService . appendText(tempDir, name, ' ' )
23
- sleep 100
21
+ FileService . appendText(rootDir, fileName, ' ' )
24
22
25
23
then :
26
- new File (tempDir, name ). text == ' '
24
+ new File (rootDir, fileName ). text == ' initial text '
27
25
}
28
26
29
27
}
Original file line number Diff line number Diff line change @@ -7,13 +7,6 @@ import java.nio.file.Files
7
7
8
8
class BaseSpec extends Specification {
9
9
10
- static File tempDir = Files . createTempDirectory(" parallel-test-execution" ). toFile()
11
-
12
- def cleanup () {
13
- tempDir. listFiles(). each {
14
- println " Removing $it "
15
- it. delete()
16
- }
17
- }
10
+ static File rootDir = Files . createTempDirectory(" parallel-test-execution" ). toFile()
18
11
19
12
}
Original file line number Diff line number Diff line change @@ -7,8 +7,7 @@ class MetricsSpec extends BaseSpec {
7
7
def count = MetricService . getInvocationsCount()
8
8
9
9
when :
10
- FileService . appendText(tempDir, " test" , " some text" )
11
- sleep 100
10
+ FileService . appendText(rootDir, " test" , " some text" )
12
11
13
12
then :
14
13
MetricService . getInvocationsCount() == count + 1
@@ -19,8 +18,7 @@ class MetricsSpec extends BaseSpec {
19
18
def count = MetricService . getInvocationsCount()
20
19
21
20
when :
22
- FileService . setText(tempDir, " test" , " some text" )
23
- sleep 100
21
+ FileService . setText(rootDir, " test" , " some text" )
24
22
25
23
then :
26
24
MetricService . getInvocationsCount() == count + 1
Original file line number Diff line number Diff line change @@ -2,28 +2,32 @@ package migration
2
2
3
3
class SetTextSpec extends BaseSpec {
4
4
5
+ def cleanup () {
6
+ rootDir. listFiles(). each {
7
+ it. delete()
8
+ }
9
+ }
10
+
5
11
def " create file with text" () {
6
12
given :
7
- def name = " test"
13
+ def fileName = " test 1 "
8
14
9
15
when :
10
- FileService . setText(tempDir, name, " some text" )
11
- sleep 200
16
+ FileService . setText(rootDir, fileName, " some text" )
12
17
13
18
then :
14
- new File (tempDir, name ). text == ' some text'
19
+ new File (rootDir, fileName ). text == ' some text'
15
20
}
16
21
17
22
def " create empty file" () {
18
23
given :
19
- def name = " test"
24
+ def fileName = " test 2 "
20
25
21
26
when :
22
- FileService . setText(tempDir, name, " " )
23
- sleep 200
27
+ FileService . setText(rootDir, fileName, " " )
24
28
25
29
then :
26
- new File (tempDir, name ). text == ' '
30
+ new File (rootDir, fileName ). text == ' '
27
31
}
28
32
29
33
}
You can’t perform that action at this time.
0 commit comments