aboutsummaryrefslogtreecommitdiff
path: root/streaming/src/test/java/org/apache
diff options
context:
space:
mode:
authorSean Owen <sowen@cloudera.com>2015-08-04 12:02:26 +0100
committerSean Owen <sowen@cloudera.com>2015-08-04 12:02:26 +0100
commit76d74090d60f74412bd45487e8db6aff2e8343a2 (patch)
treedf06579d8c0ab184fe17e1e1c611e01fcf4242a0 /streaming/src/test/java/org/apache
parent9e952ecbce670e9b532a1c664a4d03b66e404112 (diff)
downloadspark-76d74090d60f74412bd45487e8db6aff2e8343a2.tar.gz
spark-76d74090d60f74412bd45487e8db6aff2e8343a2.tar.bz2
spark-76d74090d60f74412bd45487e8db6aff2e8343a2.zip
[SPARK-9534] [BUILD] Enable javac lint for scalac parity; fix a lot of build warnings, 1.5.0 edition
Enable most javac lint warnings; fix a lot of build warnings. In a few cases, touch up surrounding code in the process. I'll explain several of the changes inline in comments. Author: Sean Owen <sowen@cloudera.com> Closes #7862 from srowen/SPARK-9534 and squashes the following commits: ea51618 [Sean Owen] Enable most javac lint warnings; fix a lot of build warnings. In a few cases, touch up surrounding code in the process.
Diffstat (limited to 'streaming/src/test/java/org/apache')
-rw-r--r--streaming/src/test/java/org/apache/spark/streaming/JavaWriteAheadLogSuite.java62
1 files changed, 32 insertions, 30 deletions
diff --git a/streaming/src/test/java/org/apache/spark/streaming/JavaWriteAheadLogSuite.java b/streaming/src/test/java/org/apache/spark/streaming/JavaWriteAheadLogSuite.java
index 50e8f9fc15..175b8a496b 100644
--- a/streaming/src/test/java/org/apache/spark/streaming/JavaWriteAheadLogSuite.java
+++ b/streaming/src/test/java/org/apache/spark/streaming/JavaWriteAheadLogSuite.java
@@ -17,13 +17,15 @@
package org.apache.spark.streaming;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.nio.ByteBuffer;
import java.util.Arrays;
-import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.Transformer;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
import org.apache.spark.SparkConf;
import org.apache.spark.streaming.util.WriteAheadLog;
import org.apache.spark.streaming.util.WriteAheadLogRecordHandle;
@@ -32,40 +34,40 @@ import org.apache.spark.streaming.util.WriteAheadLogUtils;
import org.junit.Test;
import org.junit.Assert;
-class JavaWriteAheadLogSuiteHandle extends WriteAheadLogRecordHandle {
- int index = -1;
- public JavaWriteAheadLogSuiteHandle(int idx) {
- index = idx;
- }
-}
-
public class JavaWriteAheadLogSuite extends WriteAheadLog {
- class Record {
+ static class JavaWriteAheadLogSuiteHandle extends WriteAheadLogRecordHandle {
+ int index = -1;
+ JavaWriteAheadLogSuiteHandle(int idx) {
+ index = idx;
+ }
+ }
+
+ static class Record {
long time;
int index;
ByteBuffer buffer;
- public Record(long tym, int idx, ByteBuffer buf) {
+ Record(long tym, int idx, ByteBuffer buf) {
index = idx;
time = tym;
buffer = buf;
}
}
private int index = -1;
- private ArrayList<Record> records = new ArrayList<Record>();
+ private final List<Record> records = new ArrayList<>();
// Methods for WriteAheadLog
@Override
- public WriteAheadLogRecordHandle write(java.nio.ByteBuffer record, long time) {
+ public WriteAheadLogRecordHandle write(ByteBuffer record, long time) {
index += 1;
- records.add(new org.apache.spark.streaming.JavaWriteAheadLogSuite.Record(time, index, record));
+ records.add(new Record(time, index, record));
return new JavaWriteAheadLogSuiteHandle(index);
}
@Override
- public java.nio.ByteBuffer read(WriteAheadLogRecordHandle handle) {
+ public ByteBuffer read(WriteAheadLogRecordHandle handle) {
if (handle instanceof JavaWriteAheadLogSuiteHandle) {
int reqdIndex = ((JavaWriteAheadLogSuiteHandle) handle).index;
for (Record record: records) {
@@ -78,14 +80,13 @@ public class JavaWriteAheadLogSuite extends WriteAheadLog {
}
@Override
- public java.util.Iterator<java.nio.ByteBuffer> readAll() {
- Collection<ByteBuffer> buffers = CollectionUtils.collect(records, new Transformer() {
+ public Iterator<ByteBuffer> readAll() {
+ return Iterators.transform(records.iterator(), new Function<Record,ByteBuffer>() {
@Override
- public Object transform(Object input) {
- return ((Record) input).buffer;
+ public ByteBuffer apply(Record input) {
+ return input.buffer;
}
});
- return buffers.iterator();
}
@Override
@@ -110,20 +111,21 @@ public class JavaWriteAheadLogSuite extends WriteAheadLog {
WriteAheadLog wal = WriteAheadLogUtils.createLogForDriver(conf, null, null);
String data1 = "data1";
- WriteAheadLogRecordHandle handle = wal.write(ByteBuffer.wrap(data1.getBytes()), 1234);
+ WriteAheadLogRecordHandle handle =
+ wal.write(ByteBuffer.wrap(data1.getBytes(StandardCharsets.UTF_8)), 1234);
Assert.assertTrue(handle instanceof JavaWriteAheadLogSuiteHandle);
- Assert.assertTrue(new String(wal.read(handle).array()).equals(data1));
+ Assert.assertEquals(new String(wal.read(handle).array(), StandardCharsets.UTF_8), data1);
- wal.write(ByteBuffer.wrap("data2".getBytes()), 1235);
- wal.write(ByteBuffer.wrap("data3".getBytes()), 1236);
- wal.write(ByteBuffer.wrap("data4".getBytes()), 1237);
+ wal.write(ByteBuffer.wrap("data2".getBytes(StandardCharsets.UTF_8)), 1235);
+ wal.write(ByteBuffer.wrap("data3".getBytes(StandardCharsets.UTF_8)), 1236);
+ wal.write(ByteBuffer.wrap("data4".getBytes(StandardCharsets.UTF_8)), 1237);
wal.clean(1236, false);
- java.util.Iterator<java.nio.ByteBuffer> dataIterator = wal.readAll();
- ArrayList<String> readData = new ArrayList<String>();
+ Iterator<ByteBuffer> dataIterator = wal.readAll();
+ List<String> readData = new ArrayList<>();
while (dataIterator.hasNext()) {
- readData.add(new String(dataIterator.next().array()));
+ readData.add(new String(dataIterator.next().array(), StandardCharsets.UTF_8));
}
- Assert.assertTrue(readData.equals(Arrays.asList("data3", "data4")));
+ Assert.assertEquals(readData, Arrays.asList("data3", "data4"));
}
}