-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOutputBufferTest.java
More file actions
115 lines (94 loc) · 3.59 KB
/
OutputBufferTest.java
File metadata and controls
115 lines (94 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package org.utplsql.api;
import org.junit.Rule;
import org.junit.Test;
import org.utplsql.api.reporter.DocumentationReporter;
import org.utplsql.api.reporter.OutputReporter;
import org.utplsql.api.rules.DatabaseRule;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
/**
* Created by Vinicius on 13/04/2017.
*/
public class OutputBufferTest {
@Rule
public final DatabaseRule db = new DatabaseRule();
public OutputReporter createReporter() throws SQLException {
Connection conn = db.newConnection();
OutputReporter reporter = new DocumentationReporter().init(conn);
System.out.println("Output ID: " + reporter.getOutputBuffer().getOutputId());
return reporter;
}
@Test
public void printAvailableLines() {
ExecutorService executorService = Executors.newFixedThreadPool(2);
try {
final OutputReporter reporter = createReporter();
Future<Object> task1 = executorService.submit(() -> {
try {
Connection conn = db.newConnection();
new TestRunner()
.addPath(db.getUser())
.addReporter(reporter)
.run(conn);
return Boolean.TRUE;
} catch (SQLException e) {
return e;
}
});
Future<Object> task2 = executorService.submit(() -> {
FileOutputStream fileOutStream = null;
File outFile = new File("output.txt");
try {
Connection conn = db.newConnection();
fileOutStream = new FileOutputStream(outFile);
List<PrintStream> printStreams = new ArrayList<>();
printStreams.add(System.out);
printStreams.add(new PrintStream(fileOutStream));
reporter.getOutputBuffer()
.printAvailable(conn, printStreams);
return Boolean.TRUE;
} catch (SQLException e) {
return e;
} finally {
if (fileOutStream != null) {
fileOutStream.close();
outFile.delete();
}
}
});
executorService.shutdown();
executorService.awaitTermination(60, TimeUnit.MINUTES);
Object res1 = task1.get();
Object res2 = task2.get();
if (res1 instanceof Exception)
Assert.fail(((Exception) res1).getMessage());
if (res2 instanceof Exception)
Assert.fail(((Exception) res2).getMessage());
} catch (SQLException e) {
Assert.fail(e.getMessage());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
@Test
public void fetchAllLines() {
try {
final OutputReporter reporter = createReporter();
Connection conn = db.newConnection();
new TestRunner()
.addPath(db.getUser())
.addReporter(reporter)
.run(conn);
List<String> outputLines = reporter.getOutputBuffer()
.fetchAll(conn);
Assert.assertTrue(outputLines.size() > 0);
} catch (SQLException e) {
Assert.fail(e.getMessage());
}
}
}