@@ -35,9 +35,10 @@ import org.apache.hadoop.conf.Configuration
35
35
import org .apache .hadoop .fs .Path
36
36
37
37
import org .apache .spark .network .util .ByteUnit
38
+ import org .apache .spark .Logging
38
39
import org .apache .spark .SparkConf
39
40
40
- class UtilsSuite extends FunSuite with ResetSystemProperties {
41
+ class UtilsSuite extends FunSuite with ResetSystemProperties with Logging {
41
42
42
43
test(" timeConversion" ) {
43
44
// Test -1
@@ -68,7 +69,7 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
68
69
intercept[NumberFormatException ] {
69
70
Utils .timeStringAsMs(" 600l" )
70
71
}
71
-
72
+
72
73
intercept[NumberFormatException ] {
73
74
Utils .timeStringAsMs(" This breaks 600s" )
74
75
}
@@ -99,7 +100,7 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
99
100
assert(Utils .byteStringAsGb(" 1k" ) === 0 )
100
101
assert(Utils .byteStringAsGb(" 1t" ) === ByteUnit .TiB .toGiB(1 ))
101
102
assert(Utils .byteStringAsGb(" 1p" ) === ByteUnit .PiB .toGiB(1 ))
102
-
103
+
103
104
assert(Utils .byteStringAsMb(" 1" ) === 1 )
104
105
assert(Utils .byteStringAsMb(" 1m" ) === 1 )
105
106
assert(Utils .byteStringAsMb(" 1048575b" ) === 0 )
@@ -118,7 +119,7 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
118
119
assert(Utils .byteStringAsKb(" 1g" ) === ByteUnit .GiB .toKiB(1 ))
119
120
assert(Utils .byteStringAsKb(" 1t" ) === ByteUnit .TiB .toKiB(1 ))
120
121
assert(Utils .byteStringAsKb(" 1p" ) === ByteUnit .PiB .toKiB(1 ))
121
-
122
+
122
123
assert(Utils .byteStringAsBytes(" 1" ) === 1 )
123
124
assert(Utils .byteStringAsBytes(" 1k" ) === ByteUnit .KiB .toBytes(1 ))
124
125
assert(Utils .byteStringAsBytes(" 1m" ) === ByteUnit .MiB .toBytes(1 ))
@@ -127,17 +128,17 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
127
128
assert(Utils .byteStringAsBytes(" 1p" ) === ByteUnit .PiB .toBytes(1 ))
128
129
129
130
// Overflow handling, 1073741824p exceeds Long.MAX_VALUE if converted straight to Bytes
130
- // This demonstrates that we can have e.g 1024^3 PB without overflowing.
131
+ // This demonstrates that we can have e.g 1024^3 PB without overflowing.
131
132
assert(Utils .byteStringAsGb(" 1073741824p" ) === ByteUnit .PiB .toGiB(1073741824 ))
132
133
assert(Utils .byteStringAsMb(" 1073741824p" ) === ByteUnit .PiB .toMiB(1073741824 ))
133
-
134
+
134
135
// Run this to confirm it doesn't throw an exception
135
- assert(Utils .byteStringAsBytes(" 9223372036854775807" ) === 9223372036854775807L )
136
+ assert(Utils .byteStringAsBytes(" 9223372036854775807" ) === 9223372036854775807L )
136
137
assert(ByteUnit .PiB .toPiB(9223372036854775807L ) === 9223372036854775807L )
137
-
138
+
138
139
// Test overflow exception
139
140
intercept[IllegalArgumentException ] {
140
- // This value exceeds Long.MAX when converted to bytes
141
+ // This value exceeds Long.MAX when converted to bytes
141
142
Utils .byteStringAsBytes(" 9223372036854775808" )
142
143
}
143
144
@@ -146,22 +147,22 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
146
147
// This value exceeds Long.MAX when converted to TB
147
148
ByteUnit .PiB .toTiB(9223372036854775807L )
148
149
}
149
-
150
+
150
151
// Test fractional string
151
152
intercept[NumberFormatException ] {
152
153
Utils .byteStringAsMb(" 0.064" )
153
154
}
154
-
155
+
155
156
// Test fractional string
156
157
intercept[NumberFormatException ] {
157
158
Utils .byteStringAsMb(" 0.064m" )
158
159
}
159
-
160
+
160
161
// Test invalid strings
161
162
intercept[NumberFormatException ] {
162
163
Utils .byteStringAsBytes(" 500ub" )
163
164
}
164
-
165
+
165
166
// Test invalid strings
166
167
intercept[NumberFormatException ] {
167
168
Utils .byteStringAsBytes(" This breaks 600b" )
@@ -174,12 +175,12 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
174
175
intercept[NumberFormatException ] {
175
176
Utils .byteStringAsBytes(" 600gb This breaks" )
176
177
}
177
-
178
+
178
179
intercept[NumberFormatException ] {
179
180
Utils .byteStringAsBytes(" This 123mb breaks" )
180
181
}
181
182
}
182
-
183
+
183
184
test(" bytesToString" ) {
184
185
assert(Utils .bytesToString(10 ) === " 10.0 B" )
185
186
assert(Utils .bytesToString(1500 ) === " 1500.0 B" )
@@ -475,6 +476,15 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
475
476
}
476
477
}
477
478
479
+ // Test for using the util function to change our log levels.
480
+ test(" log4j log level change" ) {
481
+ Utils .setLogLevel(org.apache.log4j.Level .ALL )
482
+ assert(log.isInfoEnabled())
483
+ Utils .setLogLevel(org.apache.log4j.Level .ERROR )
484
+ assert(! log.isInfoEnabled())
485
+ assert(log.isErrorEnabled())
486
+ }
487
+
478
488
test(" deleteRecursively" ) {
479
489
val tempDir1 = Utils .createTempDir()
480
490
assert(tempDir1.exists())
0 commit comments