Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrplaneTest.java
More file actions
Latest commit
241 lines (197 loc) · 6.71 KB
/
Copy pathErrplaneTest.java
File metadata and controls
241 lines (197 loc) · 6.71 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
packagecom.errplane.api;
importstaticorg.junit.Assert.assertFalse;
importstaticorg.junit.Assert.assertNotNull;
importstaticorg.junit.Assert.assertNull;
importstaticorg.junit.Assert.assertTrue;
importstaticorg.junit.Assert.fail;
importorg.junit.After;
importorg.junit.Before;
importorg.junit.Ignore;
importorg.junit.Test;
publicclassErrplaneTest {
@Before
publicvoidsetUp() throwsException {
StringappKey = System.getenv("EP_APP");
StringapiKey = System.getenv("EP_API");
Stringenv = System.getenv("EP_ENV");
assertTrue("Environemnt variables not set: EP_APP, EP_API, EP_ENV!",
Errplane.init(appKey, apiKey, env));
}
@After
publicvoidtearDown() throwsException {
Errplane.flush();
}
@Test
@Ignore
publicvoidinit() {
fail("Not yet implemented");
}
@Test
@Ignore
publicvoidsetUrl() {
fail("Not yet implemented");
}
@Test
@Ignore
publicvoidexceptionHashOverride() {
fail("Not yet implemented");
}
@Test
@Ignore
publicvoidsetSessionUser() {
fail("Not yet implemented");
}
@Test
@Ignore
publicvoidflush() {
fail("Not yet implemented");
}
@Test
@Ignore
publicvoidbreadcrumb() {
fail("Not yet implemented");
}
@Test
publicvoidreportString() {
assertTrue("Report with name failed!", Errplane.report("unittest_errplane_java_testReport"));
Errplane.flush();
// now try batch sends and using specified time, not 'now'
for (inti = 0; i < 10; i++) {
assertTrue("Report batch sends failed",
Errplane.report(("unittest_errplane_java_testReportBatch"+i)));
}
// try {
// Thread.sleep(30001);
// }
// catch (Exception e){}
Errplane.flush();
// create a name around the 255 character limit and test for success/failure
StringbaseName = "unittest_errplane_java_testReport_nameLimits";
for (inti = baseName.length(); i < 251; i++) {
baseName += "E";
}
Stringname = baseName + "249";
assertTrue("Report failed with name length " + name.length() + " characters.", Errplane.report(name));
name = baseName + "E2500";
assertFalse("Report succeeded with name length " + name.length() +
" characters!", Errplane.report(name));
name = baseName + "EE2511";
assertFalse("Report succeeded with name length " + name.length() +
" characters!", Errplane.report(name));
assertFalse("Report succeeded with null name!", Errplane.report(null));
}
@Test
publicvoidverifyMetricName() {
assertTrue("metric should be valid", Errplane.verifyMetricName("foobar"));
assertTrue("metric should be valid", Errplane.verifyMetricName("foobar09_."));
assertFalse("metric shouldn't be valid", Errplane.verifyMetricName("foo/bar"));
}
@Test
publicvoidaggregate() {
assertTrue("Aggregate failed!",
Errplane.aggregate("unittest_errplane_java_testAggregate", 100.0));
}
@Test
publicvoidsum() {
assertTrue("Sum failed!",
Errplane.sum("unittest_errplane_java_testSum", 100.0));
}
@Test
publicvoidreportStringInt() {
assertTrue("Report with name and int failed!",
Errplane.report("unittest_errplane_java_testReportInt", 12345));
}
@Test
publicvoidreportStringDouble() {
assertTrue("Report with name and double failed!",
Errplane.report("unittest_errplane_java_testReportDouble", 123.45));
}
@Test
publicvoidreportStringString() {
assertTrue("Report with name and context failed!",
Errplane.report("unittest_errplane_java_testReportContext", "login"));
}
@Test
publicvoidreportStringIntString() {
assertTrue("Report with name, int, and context failed!",
Errplane.report("unittest_errplane_java_testReportIntContext", 2557325, "volume"));
}
@Test
publicvoidreportStringDoubleString() {
assertTrue("Report with name, double, and context failed!",
Errplane.report("unittest_errplane_java_testReportDoubleContext", 1174.3, "mssgs/s"));
}
@Test
publicvoidreportExceptionException() {
try {
thrownewNullPointerException("TestNPE");
}
catch (NullPointerExceptione) {
assertTrue("Report Exception failed!",
Errplane.reportException(e, Errplane.getExceptionData
("unittest_errplane-java", "testException", "junit")));
}
Errplane.breadcrumb("now");
Errplane.breadcrumb("some");
Errplane.breadcrumb("breadcrumbs");
try {
thrownewClassCastException("Just some BCs, don't worry about it!");
}
catch (ClassCastExceptione) {
assertTrue("Report Exception failed!",
Errplane.reportException(e, Errplane.getExceptionData
("unittest_errplane-java", "testException", "junit")));
}
}
@Test
publicvoidreportExceptionExceptionString() {
try {
thrownewNullPointerException("TestNPE custom data");
}
catch (NullPointerExceptione) {
assertTrue("Report Exception failed!",
Errplane.reportException(e, "{\"user\":\"junit\"}", Errplane.getExceptionData
("unittest_errplane-java", "testExceptionCustomData", "junit")));
assertTrue("Report Exception failed!",
Errplane.reportException(e, "just some custom data", Errplane.getExceptionData
("unittest_errplane-java", "testExceptionCustomData", "junit")));
}
}
@Test
publicvoidreportExceptionExceptionStringString() {
try {
thrownewNullPointerException("TestNPE with Hash and custom data");
}
catch (NullPointerExceptione) {
assertTrue("Report Exception failed!",
Errplane.reportException(e, "{\"user\":\"junit\"}", Errplane.getExceptionData
("unittest_errplane-java", "testExceptionHashAndCustomData", "junit")));
}
}
@Test
publicvoidstartTimer() {
TimerTasktt = Errplane.startTimer(null);
assertNull("", tt);
// create a name around the 250 character limit and test for success/failure
StringbaseName = "unittest_errplane_java_testStartTimer_nameLimits";
for (inti = baseName.length(); i < 251; i++) {
baseName += "E";
}
Stringname = baseName + "249";
tt = Errplane.startTimer(name);
assertNotNull("startTimer failed with name length " + name.length() + " characters.", tt);
name = baseName + "E2500";
tt = Errplane.startTimer(name);
assertNull("startTimer succeeded with name length " + name.length() + " characters.", tt);
name = baseName + "EE2511";
tt = Errplane.startTimer(name);
assertNull("startTimer succeeded with name length " + name.length() + " characters.", tt);
tt = Errplane.startTimer("unittest_errplane_java_timerTest");
assertNotNull("TimerTask is null!", tt);
try {
Thread.sleep(555);
}
catch (Exceptione) {}
tt.finish();
}
}