embulk-filter-speedometer 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -4
- data/build.gradle +3 -3
- data/src/main/java/org/embulk/filter/SpeedometerFilterPlugin.java +16 -39
- data/src/main/java/org/embulk/filter/SpeedometerSpeedAggregator.java +20 -7
- data/src/main/java/org/embulk/filter/SpeedometerSpeedController.java +25 -5
- data/src/main/java/org/embulk/filter/SpeedometerUtil.java +7 -1
- data/src/test/java/org/embulk/filter/TestSpeedometerFilterPlugin.java +1 -1
- data/src/test/java/org/embulk/filter/TestSpeedometerSpeedAggregator.java +6 -0
- data/src/test/java/org/embulk/filter/TestSpeedometerSpeedController.java +37 -0
- data/src/test/java/org/embulk/filter/TestSpeedometerUtil.java +31 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 412ffe6e6afcc9ad7adcc2c3bf115ff69b46e068
|
4
|
+
data.tar.gz: 26edc64ab161aed9f413778eefb4de6e2e61fca2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49cc5903582acc3e75f80e6f4a1eeddcb6b43b9751dadbd3fa51c8367c9c47adbdc56483ad0cf0b514d3446e6984a3abe299a73d28b140197f42d8d758f8ebad
|
7
|
+
data.tar.gz: a4a89b2f63c83e0e2c222e775058aa9176f92ad7487936aa2fbf4752e74c324e1e9603a75c212df057d2f6da0fc13f73c22fdae6d1020e588f038906548436e8
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Speedometer Filter Plugin for Embulk
|
2
2
|
|
3
3
|
Write log message of processed bytes and throughput periodically.
|
4
|
+
This plugin works with embulk:0.6.17 or later versions because of removing deprecated APIs.
|
4
5
|
|
5
6
|
## Overview
|
6
7
|
|
@@ -12,6 +13,7 @@ Write log message of processed bytes and throughput periodically.
|
|
12
13
|
- **speed_limit**: Set maximum processing size per second. If 0 is set, then no limit. (integer, optional, default: 0)
|
13
14
|
- **delimiter**: Delimiter text to calculate delimiter length. (string, optional, default: ",")
|
14
15
|
- **record_padding_size**: Additional byte size for each record like a return code length. (integer, optional, default: 1)
|
16
|
+
- **column_options**: A map whose keys are name of columns like csv formatter plugin (hash, optional, default: {})
|
15
17
|
|
16
18
|
## Example of Configuration
|
17
19
|
|
@@ -50,19 +52,32 @@ filters:
|
|
50
52
|
record_padding_size: 0
|
51
53
|
```
|
52
54
|
|
55
|
+
- Set timestamp format to change default format for timestamp columns. The following **column_options** set %Y-%m-%d %H:%M:%S for time column and %Y%m%d for purchase column. If this option is not set, then a default embulk timestamp format is used.
|
56
|
+
|
57
|
+
```yaml
|
58
|
+
filters:
|
59
|
+
- type: speedometer
|
60
|
+
speed_limit: 250000
|
61
|
+
column_options:
|
62
|
+
time: {format: '%Y-%m-%d %H:%M:%S'}
|
63
|
+
purchase: {format: '%Y%m%d'}
|
64
|
+
```
|
65
|
+
|
66
|
+
|
53
67
|
## Sample Log Message
|
54
68
|
|
55
69
|
```
|
56
|
-
2015-
|
57
|
-
2015-
|
58
|
-
2015-
|
59
|
-
2015-03-07 18:29:11.410 -0800 [INFO] (task-0008): {speedometer: {active: 5, total: 36.1mb, sec: 20.0, speed: 2.7mb/s}}
|
70
|
+
2015-11-27 13:43:25.592 +0900 [INFO] (task-0006): {speedometer: {active: 4, total: 13.5mb, sec: 1:51, speed: 121kb/s, records: 269,748, record-speed: 2,435/s}}
|
71
|
+
2015-11-27 13:43:35.642 +0900 [INFO] (task-0004): {speedometer: {active: 4, total: 14.9mb, sec: 2:01, speed: 141kb/s, records: 297,532, record-speed: 2,832/s}}
|
72
|
+
2015-11-27 13:43:45.661 +0900 [INFO] (task-0005): {speedometer: {active: 3, total: 16.5mb, sec: 2:11, speed: 119kb/s, records: 329,484, record-speed: 2,395/s}}
|
60
73
|
```
|
61
74
|
|
62
75
|
- **active**: running threads
|
63
76
|
- **total**: processed bytes. This size is calculated based on text data like csv. For example, boolean value is 4 bytes(true) or 5 bytes(false). The default configuration set a byte for delimiter and a byte padding for each record.
|
64
77
|
- **sec**: elapsed time.
|
65
78
|
- **speed**: bytes per second.
|
79
|
+
- **records**: total processed records.
|
80
|
+
- **record-speed**: total processed records per second.
|
66
81
|
|
67
82
|
## Build
|
68
83
|
|
data/build.gradle
CHANGED
@@ -16,11 +16,11 @@ configurations {
|
|
16
16
|
provided
|
17
17
|
}
|
18
18
|
|
19
|
-
version = "0.
|
19
|
+
version = "0.3.0"
|
20
20
|
|
21
21
|
dependencies {
|
22
|
-
compile "org.embulk:embulk-core:0.
|
23
|
-
provided "org.embulk:embulk-core:0.
|
22
|
+
compile "org.embulk:embulk-core:0.6.17+"
|
23
|
+
provided "org.embulk:embulk-core:0.6.17+"
|
24
24
|
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
|
25
25
|
testCompile "org.jmockit:jmockit:1.15+"
|
26
26
|
testCompile "junit:junit:4.+"
|
@@ -1,5 +1,7 @@
|
|
1
1
|
package org.embulk.filter;
|
2
2
|
|
3
|
+
import java.util.Map;
|
4
|
+
|
3
5
|
import javax.validation.constraints.Min;
|
4
6
|
|
5
7
|
import org.embulk.config.Config;
|
@@ -19,9 +21,7 @@ import org.embulk.spi.PageReader;
|
|
19
21
|
import org.embulk.spi.Schema;
|
20
22
|
import org.embulk.spi.time.Timestamp;
|
21
23
|
import org.embulk.spi.time.TimestampFormatter;
|
22
|
-
import org.embulk.spi.
|
23
|
-
|
24
|
-
import com.google.common.collect.ImmutableMap;
|
24
|
+
import org.embulk.spi.util.Timestamps;
|
25
25
|
|
26
26
|
public class SpeedometerFilterPlugin
|
27
27
|
implements FilterPlugin
|
@@ -30,7 +30,7 @@ public class SpeedometerFilterPlugin
|
|
30
30
|
private static final int FALSE_LENGTH = Boolean.toString(false).length();
|
31
31
|
|
32
32
|
public interface PluginTask
|
33
|
-
extends Task, TimestampFormatter.
|
33
|
+
extends Task, TimestampFormatter.Task
|
34
34
|
{
|
35
35
|
@Config("speed_limit")
|
36
36
|
@ConfigDefault("0")
|
@@ -55,10 +55,18 @@ public class SpeedometerFilterPlugin
|
|
55
55
|
@Min(0)
|
56
56
|
public int getLogIntervalSeconds();
|
57
57
|
|
58
|
+
@Config("column_options")
|
59
|
+
@ConfigDefault("{}")
|
60
|
+
Map<String, TimestampColumnOption> getColumnOptions();
|
61
|
+
|
58
62
|
@ConfigInject
|
59
63
|
public BufferAllocator getBufferAllocator();
|
60
64
|
}
|
61
65
|
|
66
|
+
public interface TimestampColumnOption extends Task,
|
67
|
+
TimestampFormatter.TimestampColumnOption
|
68
|
+
{ }
|
69
|
+
|
62
70
|
@Override
|
63
71
|
public void transaction(ConfigSource config, Schema inputSchema,
|
64
72
|
FilterPlugin.Control control)
|
@@ -80,7 +88,7 @@ public class SpeedometerFilterPlugin
|
|
80
88
|
static class SpeedControlPageOutput implements PageOutput {
|
81
89
|
private final SpeedometerSpeedController controller;
|
82
90
|
private final Schema schema;
|
83
|
-
private final
|
91
|
+
private final TimestampFormatter[] timestampFormatters;
|
84
92
|
private final PageOutput pageOutput;
|
85
93
|
private final PageReader pageReader;
|
86
94
|
private final BufferAllocator allocator;
|
@@ -96,7 +104,7 @@ public class SpeedometerFilterPlugin
|
|
96
104
|
this.delimiterLength = task.getDelimiter().length();
|
97
105
|
this.recordPaddingSize = task.getRecordPaddingSize();
|
98
106
|
this.pageReader = new PageReader(schema);
|
99
|
-
this.
|
107
|
+
this.timestampFormatters = Timestamps.newTimestampColumnFormatters(task, schema, task.getColumnOptions());
|
100
108
|
this.pageBuilder = new PageBuilder(allocator, schema, pageOutput);
|
101
109
|
}
|
102
110
|
|
@@ -126,37 +134,6 @@ public class SpeedometerFilterPlugin
|
|
126
134
|
pageOutput.close();
|
127
135
|
}
|
128
136
|
|
129
|
-
private ImmutableMap<Column, TimestampFormatter> buildTimestampFormatterMap(final PluginTask task, Schema schema) {
|
130
|
-
final ImmutableMap.Builder<Column, TimestampFormatter> builder = new ImmutableMap.Builder<>();
|
131
|
-
|
132
|
-
schema.visitColumns(new ColumnVisitor() {
|
133
|
-
@Override
|
134
|
-
public void booleanColumn(Column column) { }
|
135
|
-
|
136
|
-
@Override
|
137
|
-
public void longColumn(Column column) { }
|
138
|
-
|
139
|
-
@Override
|
140
|
-
public void doubleColumn(Column column) { }
|
141
|
-
|
142
|
-
@Override
|
143
|
-
public void stringColumn(Column column) { }
|
144
|
-
|
145
|
-
@Override
|
146
|
-
public void timestampColumn(Column column) {
|
147
|
-
if (column.getType() instanceof TimestampType) {
|
148
|
-
TimestampType tt = (TimestampType) column.getType();
|
149
|
-
builder.put(column, new TimestampFormatter(tt.getFormat(), task));
|
150
|
-
} else {
|
151
|
-
throw new RuntimeException("Timestamp should be TimestampType.");
|
152
|
-
}
|
153
|
-
}
|
154
|
-
});
|
155
|
-
|
156
|
-
return builder.build();
|
157
|
-
}
|
158
|
-
|
159
|
-
|
160
137
|
class ColumnVisitorImpl implements ColumnVisitor {
|
161
138
|
private final PageBuilder pageBuilder;
|
162
139
|
private long startRecordTime;
|
@@ -220,7 +197,7 @@ public class SpeedometerFilterPlugin
|
|
220
197
|
}
|
221
198
|
|
222
199
|
private void speedMonitorEndRecord() {
|
223
|
-
controller.checkSpeedLimit(startRecordTime, recordPaddingSize);
|
200
|
+
controller.checkSpeedLimit(startRecordTime, recordPaddingSize, true);
|
224
201
|
}
|
225
202
|
|
226
203
|
// For null column
|
@@ -254,7 +231,7 @@ public class SpeedometerFilterPlugin
|
|
254
231
|
|
255
232
|
private Timestamp speedMonitor(Column column, Timestamp t) {
|
256
233
|
speedMonitorForDelimiter(column);
|
257
|
-
TimestampFormatter formatter =
|
234
|
+
TimestampFormatter formatter = timestampFormatters[column.getIndex()];
|
258
235
|
controller.checkSpeedLimit(startRecordTime, formatter.format(t).length());
|
259
236
|
return t;
|
260
237
|
}
|
@@ -18,6 +18,7 @@ class SpeedometerSpeedAggregator {
|
|
18
18
|
private final AtomicInteger activeControllerCount = new AtomicInteger(0);
|
19
19
|
private final AtomicLong globalStartTime = new AtomicLong(INITAL_START_TIME);
|
20
20
|
private final AtomicLong globalTotalBytes = new AtomicLong(0);
|
21
|
+
private final AtomicLong globalTotalRecords = new AtomicLong(0);
|
21
22
|
private final AtomicLong previousLogReportTimeMillisec = new AtomicLong(INITAL_START_TIME);
|
22
23
|
|
23
24
|
// TODO: We can use google's library.
|
@@ -28,7 +29,7 @@ class SpeedometerSpeedAggregator {
|
|
28
29
|
}
|
29
30
|
|
30
31
|
public SpeedometerSpeedAggregator() {
|
31
|
-
showLogMessage(activeControllerCount.get(), 0, 0, 0);
|
32
|
+
showLogMessage(activeControllerCount.get(), 0, 0, 0, 0, 0);
|
32
33
|
}
|
33
34
|
|
34
35
|
public void startController(SpeedometerSpeedController controller, long nowTime) {
|
@@ -45,6 +46,7 @@ class SpeedometerSpeedAggregator {
|
|
45
46
|
}
|
46
47
|
long runningCount = activeControllerCount.decrementAndGet();
|
47
48
|
globalTotalBytes.addAndGet(controller.getTotalBytes());
|
49
|
+
globalTotalRecords.addAndGet(controller.getTotalRecords());
|
48
50
|
|
49
51
|
// NOTE: Sometimes, there is no running thread nevertheless there are remaining tasks.
|
50
52
|
// So, this message may be output while running tasks.
|
@@ -92,6 +94,10 @@ class SpeedometerSpeedAggregator {
|
|
92
94
|
return globalTotalBytes.get();
|
93
95
|
}
|
94
96
|
|
97
|
+
long getGlobalTotalRecords() {
|
98
|
+
return globalTotalRecords.get();
|
99
|
+
}
|
100
|
+
|
95
101
|
List<SpeedometerSpeedController> getControllerList() {
|
96
102
|
List<SpeedometerSpeedController> copyList;
|
97
103
|
synchronized (controllerList) {
|
@@ -109,33 +115,40 @@ class SpeedometerSpeedAggregator {
|
|
109
115
|
private void showProgressMessage(long nowTime) {
|
110
116
|
long currentTotalSize = globalTotalBytes.get();
|
111
117
|
long currentBytesPerSec = 0;
|
118
|
+
long currentTotalRecords = globalTotalRecords.get();
|
119
|
+
long currentRecordsPerSec = 0;
|
112
120
|
for (SpeedometerSpeedController controller : getControllerList()) {
|
113
121
|
currentTotalSize += controller.getTotalBytes();
|
122
|
+
currentTotalRecords += controller.getTotalRecords();
|
114
123
|
currentBytesPerSec += controller.getPeriodBytesPerSec(nowTime);
|
124
|
+
currentRecordsPerSec += controller.getPeriodRecordsPerSec(nowTime);
|
115
125
|
}
|
116
126
|
|
117
127
|
long timeDelta = nowTime - globalStartTime.get();
|
118
128
|
timeDelta = timeDelta > 0 ? timeDelta : 1;
|
119
129
|
|
120
|
-
showLogMessage(activeControllerCount.get(), currentTotalSize, timeDelta, currentBytesPerSec);
|
130
|
+
showLogMessage(activeControllerCount.get(), currentTotalSize, timeDelta, currentBytesPerSec, currentTotalRecords, currentRecordsPerSec);
|
121
131
|
}
|
122
132
|
|
123
133
|
private void showOverallMessage() {
|
124
134
|
long timeDelta = System.currentTimeMillis() - globalStartTime.get();
|
125
135
|
timeDelta = timeDelta > 0 ? timeDelta : 1;
|
126
136
|
long bytesPerSec = (globalTotalBytes.get() * 1000) / timeDelta;
|
137
|
+
long recordsPerSec = (globalTotalRecords.get() * 1000) / timeDelta;
|
127
138
|
|
128
|
-
showLogMessage(activeControllerCount.get(), globalTotalBytes.get(), timeDelta, bytesPerSec);
|
139
|
+
showLogMessage(activeControllerCount.get(), globalTotalBytes.get(), timeDelta, bytesPerSec, globalTotalRecords.get(), recordsPerSec);
|
129
140
|
}
|
130
141
|
|
131
|
-
private void showLogMessage(int activeThreads, long totalBytes, long timeMilliSec, long bytesPerSec) {
|
142
|
+
private void showLogMessage(int activeThreads, long totalBytes, long timeMilliSec, long bytesPerSec, long totalRecords, long recordsPerSec) {
|
132
143
|
Logger logger = getLogger();
|
133
144
|
if (logger != null) {
|
134
|
-
logger.info(String.format("{speedometer: {active: %d, total: %s, sec: %s, speed: %s/s}}",
|
145
|
+
logger.info(String.format("{speedometer: {active: %d, total: %s, sec: %s, speed: %s/s, records: %s, record-speed: %s/s}}",
|
135
146
|
activeThreads,
|
136
|
-
SpeedometerUtil.
|
147
|
+
SpeedometerUtil.toByteText(totalBytes),
|
137
148
|
SpeedometerUtil.toTimeText(timeMilliSec),
|
138
|
-
SpeedometerUtil.
|
149
|
+
SpeedometerUtil.toByteText(bytesPerSec),
|
150
|
+
SpeedometerUtil.toDecimalText(totalRecords),
|
151
|
+
SpeedometerUtil.toDecimalText(recordsPerSec)));
|
139
152
|
}
|
140
153
|
}
|
141
154
|
}
|
@@ -14,6 +14,8 @@ class SpeedometerSpeedController {
|
|
14
14
|
private volatile long periodStartTime;
|
15
15
|
private volatile long periodTotalBytes;
|
16
16
|
private volatile long threadTotalBytes;
|
17
|
+
private volatile long periodTotalRecords;
|
18
|
+
private volatile long threadTotalRecords;
|
17
19
|
private volatile boolean renewFlag = true;
|
18
20
|
|
19
21
|
SpeedometerSpeedController(PluginTask task, SpeedometerSpeedAggregator aggregator) {
|
@@ -43,16 +45,24 @@ class SpeedometerSpeedController {
|
|
43
45
|
public long getTotalBytes() {
|
44
46
|
return threadTotalBytes + periodTotalBytes;
|
45
47
|
}
|
48
|
+
|
49
|
+
public long getTotalRecords() {
|
50
|
+
return threadTotalRecords + periodTotalRecords;
|
51
|
+
}
|
46
52
|
|
47
53
|
public long getPeriodBytesPerSec(long nowTime) {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
return (
|
54
|
+
return (periodTotalBytes * 1000) / getTimeDeltaMillisec(nowTime);
|
55
|
+
}
|
56
|
+
|
57
|
+
public long getPeriodRecordsPerSec(long nowTime) {
|
58
|
+
return (periodTotalRecords * 1000) / getTimeDeltaMillisec(nowTime);
|
53
59
|
}
|
54
60
|
|
55
61
|
public void checkSpeedLimit(long nowTime, long newDataSize) {
|
62
|
+
checkSpeedLimit(nowTime, newDataSize, false);
|
63
|
+
}
|
64
|
+
|
65
|
+
public void checkSpeedLimit(long nowTime, long newDataSize, boolean endRecord) {
|
56
66
|
if (startTime == 0) {
|
57
67
|
startTime = nowTime;
|
58
68
|
aggregator.startController(this, startTime);
|
@@ -64,6 +74,9 @@ class SpeedometerSpeedController {
|
|
64
74
|
}
|
65
75
|
|
66
76
|
periodTotalBytes += newDataSize;
|
77
|
+
if (endRecord) {
|
78
|
+
periodTotalRecords++;
|
79
|
+
}
|
67
80
|
aggregator.checkProgress(nowTime, logIntervalMillisec);
|
68
81
|
|
69
82
|
if (limitBytesPerSec <= 0) {
|
@@ -101,7 +114,14 @@ class SpeedometerSpeedController {
|
|
101
114
|
private void startNewPeriod(long newPeriodTime) {
|
102
115
|
threadTotalBytes += periodTotalBytes;
|
103
116
|
periodTotalBytes = 0;
|
117
|
+
threadTotalRecords += periodTotalRecords;
|
118
|
+
periodTotalRecords = 0;
|
104
119
|
periodStartTime = newPeriodTime;
|
105
120
|
}
|
121
|
+
|
122
|
+
private long getTimeDeltaMillisec(long nowTime) {
|
123
|
+
long timeDeltaMillisec = nowTime - periodStartTime;
|
124
|
+
return timeDeltaMillisec <= 0 ? 1 : timeDeltaMillisec;
|
125
|
+
}
|
106
126
|
}
|
107
127
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
package org.embulk.filter;
|
2
2
|
|
3
|
+
import java.text.NumberFormat;
|
4
|
+
|
3
5
|
public class SpeedometerUtil {
|
4
6
|
private static final int MIN_LENGTH = String.valueOf(Long.MIN_VALUE).length();
|
5
7
|
|
6
|
-
public static String
|
8
|
+
public static String toByteText(long originalNum) {
|
7
9
|
long baseNum = 1000;
|
8
10
|
long remain = 0;
|
9
11
|
float num = originalNum;
|
@@ -24,6 +26,10 @@ public class SpeedometerUtil {
|
|
24
26
|
return String.valueOf(originalNum);
|
25
27
|
}
|
26
28
|
|
29
|
+
public static String toDecimalText(long originalNum) {
|
30
|
+
return NumberFormat.getNumberInstance().format(originalNum);
|
31
|
+
}
|
32
|
+
|
27
33
|
public static String toTimeText(long timeMillisecs) {
|
28
34
|
long num = timeMillisecs;
|
29
35
|
|
@@ -73,7 +73,7 @@ public class TestSpeedometerFilterPlugin
|
|
73
73
|
builder.finish(); times = 0;
|
74
74
|
reader.nextRecord(); times = 2;
|
75
75
|
reader.setPage(page); times = 1;
|
76
|
-
schema.visitColumns(withInstanceOf(ColumnVisitor.class)); times =
|
76
|
+
schema.visitColumns(withInstanceOf(ColumnVisitor.class)); times = 1;
|
77
77
|
}};
|
78
78
|
}
|
79
79
|
|
@@ -42,6 +42,7 @@ public class TestSpeedometerSpeedAggregator {
|
|
42
42
|
public void testStopController() {
|
43
43
|
new NonStrictExpectations() {{
|
44
44
|
controller.getTotalBytes(); result = 11;
|
45
|
+
controller.getTotalRecords(); result = 5;
|
45
46
|
}};
|
46
47
|
|
47
48
|
SpeedometerSpeedAggregator aggregator = new SpeedometerSpeedAggregator();
|
@@ -51,6 +52,7 @@ public class TestSpeedometerSpeedAggregator {
|
|
51
52
|
assertEquals("Verify active controller count.", 0, aggregator.getActiveControllerCount());
|
52
53
|
assertFalse("Verify there is a registered controller.", aggregator.getControllerList().contains(controller));
|
53
54
|
assertEquals("Verify controller's total bytes are added to aggregator.", 11, aggregator.getGlobalTotalBytes());
|
55
|
+
assertEquals("Verify controller's total records are added to aggregator.", 5, aggregator.getGlobalTotalRecords());
|
54
56
|
}
|
55
57
|
|
56
58
|
@Test
|
@@ -98,7 +100,9 @@ public class TestSpeedometerSpeedAggregator {
|
|
98
100
|
new Verifications() {{
|
99
101
|
controller.renewPeriod(); times = 1;
|
100
102
|
controller.getTotalBytes(); times = 1;
|
103
|
+
controller.getTotalRecords(); times = 1;
|
101
104
|
controller.getPeriodBytesPerSec(startPeriodTime); times = 1;
|
105
|
+
controller.getPeriodRecordsPerSec(startPeriodTime); times = 1;
|
102
106
|
}};
|
103
107
|
}
|
104
108
|
|
@@ -114,7 +118,9 @@ public class TestSpeedometerSpeedAggregator {
|
|
114
118
|
new Verifications() {{
|
115
119
|
controller.renewPeriod(); times = 0;
|
116
120
|
controller.getTotalBytes(); times = 0;
|
121
|
+
controller.getTotalRecords(); times = 0;
|
117
122
|
controller.getPeriodBytesPerSec(startPeriodTime); times = 0;
|
123
|
+
controller.getPeriodRecordsPerSec(startPeriodTime); times = 0;
|
118
124
|
}};
|
119
125
|
}
|
120
126
|
}
|
@@ -111,4 +111,41 @@ public class TestSpeedometerSpeedController {
|
|
111
111
|
assertTrue("Verify renewPeriod flag is set.", controller.isRenewPeriodSet());
|
112
112
|
}
|
113
113
|
|
114
|
+
@Test
|
115
|
+
public void testGetTotalRecords() {
|
116
|
+
new NonStrictExpectations() {{
|
117
|
+
task.getSpeedLimit(); result = 1L;
|
118
|
+
task.getMaxSleepMillisec(); result = 2;
|
119
|
+
task.getLogIntervalSeconds(); result = 3;
|
120
|
+
aggregator.getSpeedLimitForController((SpeedometerSpeedController)any); result = 10000;
|
121
|
+
}};
|
122
|
+
long nowTime = System.currentTimeMillis();
|
123
|
+
int newDataSize = 3;
|
124
|
+
|
125
|
+
controller = new SpeedometerSpeedController(task, aggregator);
|
126
|
+
assertEquals("Verify total records is zero.", 0, controller.getTotalRecords());
|
127
|
+
controller.checkSpeedLimit(nowTime, newDataSize);
|
128
|
+
assertEquals("Verify total records is zero for no new record.", 0, controller.getTotalRecords());
|
129
|
+
controller.checkSpeedLimit(nowTime + 1, newDataSize, true);
|
130
|
+
assertEquals("Verify total records", 1, controller.getTotalRecords());
|
131
|
+
}
|
132
|
+
|
133
|
+
@Test
|
134
|
+
public void testGetPeriodRecordsPerSec() {
|
135
|
+
new NonStrictExpectations() {{
|
136
|
+
task.getSpeedLimit(); result = 1L;
|
137
|
+
task.getMaxSleepMillisec(); result = 2;
|
138
|
+
task.getLogIntervalSeconds(); result = 3;
|
139
|
+
aggregator.getSpeedLimitForController((SpeedometerSpeedController)any); result = 10000;
|
140
|
+
}};
|
141
|
+
long nowTime = System.currentTimeMillis();
|
142
|
+
int newDataSize = 3;
|
143
|
+
|
144
|
+
controller = new SpeedometerSpeedController(task, aggregator);
|
145
|
+
assertEquals("Verify total records/s", 0, controller.getPeriodRecordsPerSec(System.currentTimeMillis()));
|
146
|
+
controller.checkSpeedLimit(nowTime, newDataSize);
|
147
|
+
assertEquals("Verify total records/s is not changed", 0, controller.getPeriodRecordsPerSec(System.currentTimeMillis()));
|
148
|
+
controller.checkSpeedLimit(nowTime, newDataSize, true);
|
149
|
+
assertTrue("Verify total records/s is changed", controller.getPeriodRecordsPerSec(System.currentTimeMillis()) > 0);
|
150
|
+
}
|
114
151
|
}
|
@@ -7,20 +7,37 @@ import org.junit.Test;
|
|
7
7
|
public class TestSpeedometerUtil {
|
8
8
|
|
9
9
|
@Test
|
10
|
-
public void
|
11
|
-
assertEquals("Verify 0 bytes", "0.0b", SpeedometerUtil.
|
12
|
-
assertEquals("Verify 0 bytes", "100b", SpeedometerUtil.
|
13
|
-
assertEquals("Verify 0 bytes", "1.0kb", SpeedometerUtil.
|
14
|
-
assertEquals("Verify 0 bytes", "100kb", SpeedometerUtil.
|
15
|
-
assertEquals("Verify 0 bytes", "1.0mb", SpeedometerUtil.
|
16
|
-
assertEquals("Verify 0 bytes", "100mb", SpeedometerUtil.
|
17
|
-
assertEquals("Verify 0 bytes", "1.0gb", SpeedometerUtil.
|
18
|
-
assertEquals("Verify 0 bytes", "100gb", SpeedometerUtil.
|
19
|
-
assertEquals("Verify 0 bytes", "1.0tb", SpeedometerUtil.
|
20
|
-
assertEquals("Verify 0 bytes", "100tb", SpeedometerUtil.
|
21
|
-
assertEquals("Verify 0 bytes", "1.0pb", SpeedometerUtil.
|
22
|
-
assertEquals("Verify 0 bytes", "100pb", SpeedometerUtil.
|
23
|
-
assertEquals("Verify 0 bytes", "1.0eb", SpeedometerUtil.
|
10
|
+
public void testToByteText() {
|
11
|
+
assertEquals("Verify 0 bytes", "0.0b", SpeedometerUtil.toByteText(0));
|
12
|
+
assertEquals("Verify 0 bytes", "100b", SpeedometerUtil.toByteText(100));
|
13
|
+
assertEquals("Verify 0 bytes", "1.0kb", SpeedometerUtil.toByteText(1000L));
|
14
|
+
assertEquals("Verify 0 bytes", "100kb", SpeedometerUtil.toByteText(1000L * 100));
|
15
|
+
assertEquals("Verify 0 bytes", "1.0mb", SpeedometerUtil.toByteText(1000L * 1000));
|
16
|
+
assertEquals("Verify 0 bytes", "100mb", SpeedometerUtil.toByteText(1000L * 1000 * 100));
|
17
|
+
assertEquals("Verify 0 bytes", "1.0gb", SpeedometerUtil.toByteText(1000L * 1000 * 1000));
|
18
|
+
assertEquals("Verify 0 bytes", "100gb", SpeedometerUtil.toByteText(1000L * 1000 * 1000 * 100));
|
19
|
+
assertEquals("Verify 0 bytes", "1.0tb", SpeedometerUtil.toByteText(1000L * 1000 * 1000 * 1000));
|
20
|
+
assertEquals("Verify 0 bytes", "100tb", SpeedometerUtil.toByteText(1000L * 1000 * 1000 * 1000 * 100));
|
21
|
+
assertEquals("Verify 0 bytes", "1.0pb", SpeedometerUtil.toByteText(1000L * 1000 * 1000 * 1000 * 1000));
|
22
|
+
assertEquals("Verify 0 bytes", "100pb", SpeedometerUtil.toByteText(1000L * 1000 * 1000 * 1000 * 1000 * 100));
|
23
|
+
assertEquals("Verify 0 bytes", "1.0eb", SpeedometerUtil.toByteText(1000L * 1000 * 1000 * 1000 * 1000 * 1000));
|
24
|
+
}
|
25
|
+
|
26
|
+
@Test
|
27
|
+
public void testToDecimalText() {
|
28
|
+
assertEquals("Verify 0 bytes", "0", SpeedometerUtil.toDecimalText(0));
|
29
|
+
assertEquals("Verify 0 bytes", "100", SpeedometerUtil.toDecimalText(100));
|
30
|
+
assertEquals("Verify 0 bytes", "1,000", SpeedometerUtil.toDecimalText(1000L));
|
31
|
+
assertEquals("Verify 0 bytes", "100,000", SpeedometerUtil.toDecimalText(1000L * 100));
|
32
|
+
assertEquals("Verify 0 bytes", "1,000,000", SpeedometerUtil.toDecimalText(1000L * 1000));
|
33
|
+
assertEquals("Verify 0 bytes", "100,000,000", SpeedometerUtil.toDecimalText(1000L * 1000 * 100));
|
34
|
+
assertEquals("Verify 0 bytes", "1,000,000,000", SpeedometerUtil.toDecimalText(1000L * 1000 * 1000));
|
35
|
+
assertEquals("Verify 0 bytes", "100,000,000,000", SpeedometerUtil.toDecimalText(1000L * 1000 * 1000 * 100));
|
36
|
+
assertEquals("Verify 0 bytes", "1,000,000,000,000", SpeedometerUtil.toDecimalText(1000L * 1000 * 1000 * 1000));
|
37
|
+
assertEquals("Verify 0 bytes", "100,000,000,000,000", SpeedometerUtil.toDecimalText(1000L * 1000 * 1000 * 1000 * 100));
|
38
|
+
assertEquals("Verify 0 bytes", "1,000,000,000,000,000", SpeedometerUtil.toDecimalText(1000L * 1000 * 1000 * 1000 * 1000));
|
39
|
+
assertEquals("Verify 0 bytes", "100,000,000,000,000,000", SpeedometerUtil.toDecimalText(1000L * 1000 * 1000 * 1000 * 1000 * 100));
|
40
|
+
assertEquals("Verify 0 bytes", "1,000,000,000,000,000,000", SpeedometerUtil.toDecimalText(1000L * 1000 * 1000 * 1000 * 1000 * 1000));
|
24
41
|
}
|
25
42
|
|
26
43
|
@Test
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-filter-speedometer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,7 +62,7 @@ files:
|
|
62
62
|
- src/test/java/org/embulk/filter/TestSpeedometerSpeedAggregator.java
|
63
63
|
- src/test/java/org/embulk/filter/TestSpeedometerSpeedController.java
|
64
64
|
- src/test/java/org/embulk/filter/TestSpeedometerUtil.java
|
65
|
-
- classpath/embulk-filter-speedometer-0.
|
65
|
+
- classpath/embulk-filter-speedometer-0.3.0.jar
|
66
66
|
homepage: https://github.com/hata/embulk-filter-speedometer
|
67
67
|
licenses:
|
68
68
|
- MIT
|