From d0da6fab46c39b806a063a40d52e7c18cb082286 Mon Sep 17 00:00:00 2001 From: Mark Watson Date: Thu, 14 Jul 2016 00:54:56 -0700 Subject: [PATCH] Work with released version of Java-Websocket. Add script to order pizza. --- .gitmodules | 3 - BUILD.md | 39 +++++------ LICENSE.BSD | 2 +- build.gradle | 9 +-- gulpfile.js | 13 ++-- script-editor/src/dist/readme.txt | 15 +--- .../script/engine/EngineContext.java | 3 +- .../chrome/extension/pizza/commands.js | 4 +- .../script/tester/server/TestServer.java | 1 - script/pizza.js | 14 ++++ settings.gradle | 4 -- .../java/com/loadtestgo/util/DoubleArray.java | 62 ----------------- .../java/com/loadtestgo/util/FloatArray.java | 62 ----------------- .../main/java/com/loadtestgo/util/Guid.java | 7 -- .../src/main/java/com/loadtestgo/util/IO.java | 42 ----------- .../java/com/loadtestgo/util/IntArray.java | 66 ------------------ .../java/com/loadtestgo/util/Logging.java | 16 ----- .../java/com/loadtestgo/util/LongArray.java | 69 ------------------- .../java/com/loadtestgo/util/LongBuffer.java | 65 ----------------- .../java/com/loadtestgo/util/MathUtils.java | 7 -- .../java/com/loadtestgo/util/NetworkInfo.java | 29 -------- .../com/loadtestgo/util/ResourceUtils.java | 8 --- .../com/loadtestgo/util/RetryRunnable.java | 22 ------ .../java/com/loadtestgo/util/ThreadNamer.java | 21 ------ .../java/com/loadtestgo/util/TimeFormat.java | 22 ------ .../main/java/com/loadtestgo/util/Zip.java | 69 ------------------- .../com/loadtestgo/util/LongBufferTest.java | 55 --------------- 27 files changed, 49 insertions(+), 680 deletions(-) delete mode 100644 .gitmodules create mode 100644 script/pizza.js delete mode 100644 util/src/main/java/com/loadtestgo/util/DoubleArray.java delete mode 100644 util/src/main/java/com/loadtestgo/util/FloatArray.java delete mode 100644 util/src/main/java/com/loadtestgo/util/Guid.java delete mode 100644 util/src/main/java/com/loadtestgo/util/IO.java delete mode 100644 util/src/main/java/com/loadtestgo/util/IntArray.java delete mode 100644 util/src/main/java/com/loadtestgo/util/Logging.java delete mode 100644 util/src/main/java/com/loadtestgo/util/LongArray.java delete mode 100644 util/src/main/java/com/loadtestgo/util/LongBuffer.java delete mode 100644 util/src/main/java/com/loadtestgo/util/MathUtils.java delete mode 100644 util/src/main/java/com/loadtestgo/util/NetworkInfo.java delete mode 100644 util/src/main/java/com/loadtestgo/util/RetryRunnable.java delete mode 100644 util/src/main/java/com/loadtestgo/util/ThreadNamer.java delete mode 100644 util/src/main/java/com/loadtestgo/util/TimeFormat.java delete mode 100644 util/src/main/java/com/loadtestgo/util/Zip.java delete mode 100644 util/src/test/java/com/loadtestgo/util/LongBufferTest.java diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 573f99a..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "vendor/Java-WebSocket"] - path = vendor/Java-WebSocket - url = https://github.com/TooTallNate/Java-WebSocket diff --git a/BUILD.md b/BUILD.md index 8432ba6..d4ccfb0 100644 --- a/BUILD.md +++ b/BUILD.md @@ -6,27 +6,24 @@ ## Build - git clone --recursive git://git@watsonmw.com/home/git/pizzascript.git - -The "--recursive" is need to download the vendor submodule(s). - - cd pizzascript + git clone git://git@watsonmw.com/home/git/pizzascript.git + cd pizzascript To build the script editor package: - gradle script-editor:distZip + gradle script-editor:distZip This will save a zip file to: - script-editor/build/distributions/script-editor-0.2.zip + script-editor/build/distributions/script-editor-0.2.zip To build a flat dir: - gradle pizzascript-editor:install + gradle pizzascript-editor:install This will package run scripts and all dependent Jars to the following directory: - pizzascript-editor/build/install/script-editor + pizzascript-editor/build/install/script-editor ## Release Packaging @@ -36,31 +33,31 @@ Release mode requires NodeJS & Gulp to minify the JS files (NodeJS is also neede Install NodeJS 0.12+: On OSX: - brew install nodejs + brew install nodejs On Debian (replace \_ with just the underscore): - curl -sL https://deb.nodesource.com/setup\_0.12 | sudo bash - - sudo apt-get install nodejs + curl -sL https://deb.nodesource.com/setup\_0.12 | sudo bash - + sudo apt-get install nodejs Install Gulp as follows (sudo is necessary): - npm install --global gulp - npm install --save-dev gulp - npm install gulp-uglify gulp-concat gulp-replace event-stream --save-dev + npm install --global gulp + npm install --save-dev gulp + npm install gulp-uglify gulp-concat gulp-replace event-stream --save-dev To generate a release build: - gradle clean script-editor:distZip -Prelease + gradle clean script-editor:distZip -Prelease Build docs: - npm install jsdoc3 - npm install https://github.com/hegemonic/baseline/tarball/master - gradle docs + npm install jsdoc3 + npm install https://github.com/hegemonic/baseline/tarball/master + gradle docs ## Run Run script-editor and this will bring up an interactive JavaScript console. - >> b = pizza.open("www.google.com"); - >> b.verifyText("Search") + b = pizza.open("www.google.com"); + b.verifyText("Search") diff --git a/LICENSE.BSD b/LICENSE.BSD index 7bc247f..f0a0154 100644 --- a/LICENSE.BSD +++ b/LICENSE.BSD @@ -11,7 +11,7 @@ modification, are permitted provided that the following conditions are met: 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by the LoadTestGo, Inc -4. Neither the name 'LoadTestGo', the name 'automate', nor the names of +4. Neither the name 'LoadTestGo', the name 'PizzaScript', nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/build.gradle b/build.gradle index 75a20cd..fae9674 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,3 @@ -import org.apache.tools.ant.taskdefs.condition.Os - subprojects { apply plugin: 'java' apply plugin: 'idea' @@ -8,9 +6,6 @@ subprojects { sourceCompatibility = 1.8 targetCompatibility = 1.8 - String javaHome = System.properties.'java.home'; - options.bootClasspath = javaHome + "/lib/rt.jar:" + javaHome + "/lib/jce.jar" - // Make sure warnings are on options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } @@ -66,13 +61,13 @@ project(':script-engine') { dependencies { compile project(':script-api') compile project(':util') - compile project(':java-websocket') compile "org.mozilla:rhino:$rhinoVersion" compile 'commons-io:commons-io:2.4' compile 'javax.servlet:javax.servlet-api:3.1.0' compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion" compile 'org.json:json:20140107' compile 'com.google.collections:google-collections:1.0' + compile 'org.java-websocket:Java-WebSocket:1.3.0' } if (project.hasProperty("release")) { @@ -89,7 +84,7 @@ project(':script-engine') { project(':script-editor') { apply plugin: 'application' - mainClassName = "com.loadtestgo.script.editor.ScriptEditor" + mainClassName = "com.loadtestgo.script.editor.PizzaScript" configurations.all { resolutionStrategy { failOnVersionConflict() diff --git a/gulpfile.js b/gulpfile.js index 77267e7..1727fc0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,11 +11,12 @@ var replace = require('gulp-replace'); gulp.task('enginejs', function() { var tasks = []; - var src = 'script-engine/src/main/resources/chrome/extension/pizza/' + var src = 'script-engine/src/main/resources/chrome/extension/pizza/'; var dest = 'script-engine/build/resources/main/chrome/extension/pizza/'; + var i, r; var copyDirect = ['config.js', 'namespace.js', 'content.js']; - for (var i = 0; i < copyDirect.length; ++i) { + for (i = 0; i < copyDirect.length; ++i) { copyDirect[i] = src + copyDirect[i]; } @@ -44,8 +45,8 @@ gulp.task('enginejs', function() { return r; } - for (var i = 0; i < l.length; ++i) { - var r = l[i]; + for (i = 0; i < l.length; ++i) { + r = l[i]; r = cleanString(r); if (r != "namespace.js" && r != "config.js") { r = src + r; @@ -64,8 +65,8 @@ gulp.task('enginejs', function() { l = f.split(","); files = []; - for (var i = 0; i < l.length; ++i) { - var r = l[i]; + for (i = 0; i < l.length; ++i) { + r = l[i]; r = cleanString(r); files.push(src + r); } diff --git a/script-editor/src/dist/readme.txt b/script-editor/src/dist/readme.txt index 715ac84..769212e 100644 --- a/script-editor/src/dist/readme.txt +++ b/script-editor/src/dist/readme.txt @@ -1,24 +1,13 @@ -License -------- - -Copyright (c) 2015 Mark Watson (watsonmw@gmail.com) - -Not available for use without permission. - -No implied warranty. - - Requirements ------------ + Java 8 + Chrome 40+ (*) -Only tested on OSX, YMMV. - * Works with Stable and Release channels for the most part, but the block* and redirect* functions are only supported on the Dev Channel right now. + Setup ----- @@ -27,6 +16,7 @@ generally find it. Failing this you can set the path to Chrome (and other setti in the settings.ini file. See the settings.ini file included with this download for details. + Running ------- @@ -47,7 +37,6 @@ Run the interactive console: > bin/script-editor -console - Example Scripts -------------- diff --git a/script-engine/src/main/java/com/loadtestgo/script/engine/EngineContext.java b/script-engine/src/main/java/com/loadtestgo/script/engine/EngineContext.java index c1ed232..c907b10 100644 --- a/script-engine/src/main/java/com/loadtestgo/script/engine/EngineContext.java +++ b/script-engine/src/main/java/com/loadtestgo/script/engine/EngineContext.java @@ -6,6 +6,7 @@ import java.net.Inet4Address; import java.net.InetAddress; import java.util.ArrayList; +import java.io.IOException; /** * The main EngineContext that is shared between multiple browsers all @@ -45,7 +46,7 @@ public synchronized void cleanup() { if (webSocketServer != null) { webSocketServer.stop(3000); } - } catch (InterruptedException e) { + } catch (InterruptedException|IOException e) { Logger.error(e, "while cleaning up"); } } diff --git a/script-engine/src/main/resources/chrome/extension/pizza/commands.js b/script-engine/src/main/resources/chrome/extension/pizza/commands.js index 1bc0e2d..33c4ae2 100644 --- a/script-engine/src/main/resources/chrome/extension/pizza/commands.js +++ b/script-engine/src/main/resources/chrome/extension/pizza/commands.js @@ -987,7 +987,9 @@ pizza.main.commands = function() { function formatWasThrownException(response) { var t; - if (response.exceptionDetails) { + if (response.result.value) { + return response.result.value; + } else if (response.exceptionDetails) { t = response.exceptionDetails.text; var uncaught = "Uncaught "; if (t.indexOf(uncaught) == 0) { diff --git a/script-tester/src/main/java/com/loadtestgo/script/tester/server/TestServer.java b/script-tester/src/main/java/com/loadtestgo/script/tester/server/TestServer.java index e18c693..f390ed7 100644 --- a/script-tester/src/main/java/com/loadtestgo/script/tester/server/TestServer.java +++ b/script-tester/src/main/java/com/loadtestgo/script/tester/server/TestServer.java @@ -85,7 +85,6 @@ public void start() throws IOException { pageRegistry.registerClass(WeirdUrls.class, "/urls"); pageRegistry.registerClass(Redirects.class, "/redirect"); pageRegistry.registerClass(Timeouts.class, "/timeouts"); - pageRegistry.registerClass(TestApi.class, "/test-api"); pageRegistry.registerClass(WebRtcApi.class, "/webrtc-api"); pageRegistry.registerClass(Posts.class, "/post"); pageRegistry.registerClass(Headers.class, "/headers"); diff --git a/script/pizza.js b/script/pizza.js new file mode 100644 index 0000000..d2bc078 --- /dev/null +++ b/script/pizza.js @@ -0,0 +1,14 @@ +var b = pizza.open("https://themenustar.com/webspace/menus.php?code=newyorkerpizzeria.mobile-webview.com"); +b.click("a:contains(CRAFT PIZZA)"); + +css = "h4:contains(Large San Diego Craft Pizza)"; +b.waitForVisible(css); + +b.click(css); +css = "#option_36576"; +b.waitForVisible(css); +b.click(css); + +b.click("#option_36600"); +b.click("#option_36580"); +b.click("button:contains(Add To Cart)"); diff --git a/settings.gradle b/settings.gradle index 49a9718..cd7afaa 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,7 +4,3 @@ include "script-engine" include "script-tester" include "util" include "view-metrics" - -// Vendor libs -include ':java-websocket' -project(':java-websocket').projectDir = new File(rootProject.projectDir, 'vendor/Java-WebSocket') diff --git a/util/src/main/java/com/loadtestgo/util/DoubleArray.java b/util/src/main/java/com/loadtestgo/util/DoubleArray.java deleted file mode 100644 index 255da74..0000000 --- a/util/src/main/java/com/loadtestgo/util/DoubleArray.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.loadtestgo.util; - -import java.util.Arrays; - -public class DoubleArray { - private double[] data; - private int size; - - public DoubleArray() { - data = new double[32]; - size = 0; - } - - public DoubleArray(int capacity) { - data = new double[capacity]; - size = 0; - } - - public void add(double val) { - size += 1; - if (size >= data.length) { - double[] newData = new double[data.length * 2]; - for (int i = 0; i < data.length; ++i) { - newData[i] = data[i]; - } - data = newData; - } - data[size - 1] = val; - } - - public double[] data() { - return data; - } - - public int size() { - return size; - } - - public void sort() { - Arrays.sort(data, 0, size); - } - - public void clear() { - size = 0; - } - - public double percentile(double v) { - int index = (int)Math.floor(size * v); - return data[index]; - } - - public double mean() { - double mean = 0; - if (size == 0) { - return 0; - } - for (int i = 0; i < size; ++i) { - mean += data[i]; - } - return (mean / size); - } -} diff --git a/util/src/main/java/com/loadtestgo/util/FloatArray.java b/util/src/main/java/com/loadtestgo/util/FloatArray.java deleted file mode 100644 index b8cf334..0000000 --- a/util/src/main/java/com/loadtestgo/util/FloatArray.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.loadtestgo.util; - -import java.util.Arrays; - -public class FloatArray { - private float[] data; - private int size; - - public FloatArray() { - data = new float[32]; - size = 0; - } - - public FloatArray(int capacity) { - data = new float[capacity]; - size = 0; - } - - public void add(float val) { - size += 1; - if (size >= data.length) { - float[] newData = new float[data.length * 2]; - for (int i = 0; i < data.length; ++i) { - newData[i] = data[i]; - } - data = newData; - } - data[size - 1] = val; - } - - public float[] data() { - return data; - } - - public int size() { - return size; - } - - public void sort() { - Arrays.sort(data, 0, size); - } - - public void clear() { - size = 0; - } - - public float percentile(float v) { - int index = (int)Math.floor(size * v); - return data[index]; - } - - public float mean() { - float mean = 0; - if (size == 0) { - return 0; - } - for (int i = 0; i < size; ++i) { - mean += data[i]; - } - return (mean / size); - } -} diff --git a/util/src/main/java/com/loadtestgo/util/Guid.java b/util/src/main/java/com/loadtestgo/util/Guid.java deleted file mode 100644 index 1ca3d77..0000000 --- a/util/src/main/java/com/loadtestgo/util/Guid.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.loadtestgo.util; - -public class Guid { - static public String gen() { - return java.util.UUID.randomUUID().toString().replaceAll("-", ""); - } -} diff --git a/util/src/main/java/com/loadtestgo/util/IO.java b/util/src/main/java/com/loadtestgo/util/IO.java deleted file mode 100644 index 4d2fa1e..0000000 --- a/util/src/main/java/com/loadtestgo/util/IO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.loadtestgo.util; - -import java.io.*; - -public class IO { - public static byte[] readToByteBuffer(InputStream inStream) throws IOException { - final int bufferSize = 1024 * 10; - byte[] buffer = new byte[bufferSize]; - ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize); - int read; - while (true) { - read = inStream.read(buffer); - if (read == -1) { - break; - } - outStream.write(buffer, 0, read); - } - return outStream.toByteArray(); - } - - public static String readFully(InputStream is) throws IOException { - return readFully(is, 1024); - } - - public static String readFully(InputStream is, int bufferSize) throws IOException { - char[] buffer = new char[bufferSize]; - StringBuilder out = new StringBuilder(); - try (Reader in = new InputStreamReader(is, "UTF-8")) { - while (true) { - int rsz = in.read(buffer, 0, buffer.length); - if (rsz < 0) { - break; - } - out.append(buffer, 0, rsz); - } - } catch (UnsupportedEncodingException e) { - /* Yes, eat it */ - } - - return out.toString(); - } -} diff --git a/util/src/main/java/com/loadtestgo/util/IntArray.java b/util/src/main/java/com/loadtestgo/util/IntArray.java deleted file mode 100644 index ac8bdca..0000000 --- a/util/src/main/java/com/loadtestgo/util/IntArray.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.loadtestgo.util; - -import java.util.Arrays; - -public class IntArray { - private int[] data; - private int size; - - public IntArray() { - data = new int[32]; - size = 0; - } - - public IntArray(int capacity) { - data = new int[capacity]; - size = 0; - } - - public void add(int val) { - size += 1; - if (size >= data.length) { - int[] newData = new int[data.length * 2]; - for (int i = 0; i < data.length; ++i) { - newData[i] = data[i]; - } - data = newData; - } - data[size - 1] = val; - } - - public int[] data() { - return data; - } - - public int size() { - return size; - } - - public void sort() { - Arrays.sort(data, 0, size); - } - - public void clear() { - size = 0; - } - - public int percentile(float v) { - int index = (int)Math.floor(size * v); - return data[index]; - } - - public int mean() { - long mean = 0; - if (size == 0) { - return 0; - } - for (int i = 0; i < size; ++i) { - mean += data[i]; - } - return (int)(mean / size); - } - - public int[] copyData() { - return Arrays.copyOf(data, size); - } -} \ No newline at end of file diff --git a/util/src/main/java/com/loadtestgo/util/Logging.java b/util/src/main/java/com/loadtestgo/util/Logging.java deleted file mode 100644 index 60aae20..0000000 --- a/util/src/main/java/com/loadtestgo/util/Logging.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.loadtestgo.util; - -import java.util.logging.Level; - -public class Logging { - public static void disable(Class... classes) { - for (Class c : classes) { - disable(c.getName()); - } - } - - public static void disable(String name) { - java.util.logging.Logger logger = java.util.logging.Logger.getLogger(name); - logger.setLevel(Level.OFF); - } -} diff --git a/util/src/main/java/com/loadtestgo/util/LongArray.java b/util/src/main/java/com/loadtestgo/util/LongArray.java deleted file mode 100644 index eaacdf5..0000000 --- a/util/src/main/java/com/loadtestgo/util/LongArray.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.loadtestgo.util; - -import java.util.Arrays; - -public class LongArray { - - private long[] data; - private int size; - - public LongArray() { - data = new long[32]; - size = 0; - } - - public LongArray(int capacity) { - data = new long[capacity]; - size = 0; - } - - public void add(long val) { - size += 1; - if (size >= data.length) { - long[] newData = new long[data.length * 2]; - for (int i = 0; i < data.length; ++i) { - newData[i] = data[i]; - } - data = newData; - } - data[size - 1] = val; - } - - public int capacity() { return data.length; } - - public long[] data() { - return data; - } - - public int size() { - return size; - } - - public void sort() { - Arrays.sort(data, 0, size); - } - - public void clear() { - size = 0; - } - - public long percentile(float v) { - int index = (int)Math.floor(size * v); - return data[index]; - } - - public long mean() { - long mean = 0; - if (size == 0) { - return 0; - } - for (int i = 0; i < size; ++i) { - mean += data[i]; - } - return (int)(mean / size); - } - - public long[] copyData() { - return Arrays.copyOf(data, size); - } -} diff --git a/util/src/main/java/com/loadtestgo/util/LongBuffer.java b/util/src/main/java/com/loadtestgo/util/LongBuffer.java deleted file mode 100644 index 4d1d969..0000000 --- a/util/src/main/java/com/loadtestgo/util/LongBuffer.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.loadtestgo.util; - -public class LongBuffer { - private long[] data; - private int size; - private int pos; - - public LongBuffer() { - data = new long[32]; - size = 0; - pos = -1; - } - - public LongBuffer(int capacity) { - data = new long[capacity]; - size = 0; - pos = -1; - } - - public void add(long val) { - pos++; - - if (pos == data.length) { - pos = 0; - } - - if (pos >= size) { - size++; - } - - data[pos] = val; - } - - public long[] data() { - return data; - } - - public int size() { - return size; - } - - public int capacity() { return data.length; } - - public int begin() { - if (size < data.length) { - return 0; - } else if (pos + 1 == size) { - return 0; - } else { - return pos + 1; - } - } - - public int end() { - return pos; - } - - public long beginValue() { - return data[begin()]; - } - - public long endValue() { - return data[end()]; - } -} diff --git a/util/src/main/java/com/loadtestgo/util/MathUtils.java b/util/src/main/java/com/loadtestgo/util/MathUtils.java deleted file mode 100644 index e86d599..0000000 --- a/util/src/main/java/com/loadtestgo/util/MathUtils.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.loadtestgo.util; - -public class MathUtils { - public static int divideRoundUp(int num, int div) { - return (num + (div - 1)) / div; - } -} diff --git a/util/src/main/java/com/loadtestgo/util/NetworkInfo.java b/util/src/main/java/com/loadtestgo/util/NetworkInfo.java deleted file mode 100644 index 512de29..0000000 --- a/util/src/main/java/com/loadtestgo/util/NetworkInfo.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.loadtestgo.util; - -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.ArrayList; -import java.util.Enumeration; - -public class NetworkInfo { - public static ArrayList getInetAddrFor(String interfaceName) { - try { - ArrayList addrs = new ArrayList<>(); - Enumeration e = NetworkInterface.getNetworkInterfaces(); - while (e.hasMoreElements()) { - NetworkInterface network = (NetworkInterface)e.nextElement(); - if (network.getName().equals(interfaceName)) { - Enumeration ee = network.getInetAddresses(); - while (ee.hasMoreElements()) { - InetAddress ip = (InetAddress) ee.nextElement(); - addrs.add(ip); - } - } - } - return addrs; - } catch (SocketException e1) { - return null; - } - } -} diff --git a/util/src/main/java/com/loadtestgo/util/ResourceUtils.java b/util/src/main/java/com/loadtestgo/util/ResourceUtils.java index 87f61e8..b267a4b 100644 --- a/util/src/main/java/com/loadtestgo/util/ResourceUtils.java +++ b/util/src/main/java/com/loadtestgo/util/ResourceUtils.java @@ -48,12 +48,4 @@ public static void copyJarDirectory(File destination, JarURLConnection jarConnec } } } - - public static String loadResourceAsString(Class klass, String filename) throws IOException { - InputStream stream = klass.getResourceAsStream(filename); - if (stream == null) { - throw new IOException(String.format("Unable to laod %s", filename)); - } - return IOUtils.toString(stream); - } } diff --git a/util/src/main/java/com/loadtestgo/util/RetryRunnable.java b/util/src/main/java/com/loadtestgo/util/RetryRunnable.java deleted file mode 100644 index fadf532..0000000 --- a/util/src/main/java/com/loadtestgo/util/RetryRunnable.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.loadtestgo.util; - -import org.pmw.tinylog.Logger; - -public abstract class RetryRunnable implements Runnable { - @Override - public void run() { - boolean bInterrupted = false; - while (!bInterrupted) { - try { - runSafely(); - } catch (InterruptedException e) { - Logger.error(e, "{}: interrupted, exiting...", Thread.currentThread().getName()); - bInterrupted = true; - } catch (Throwable t) { - Logger.error(t, "{}: Caught exception and retrying...", Thread.currentThread().getName()); - } - } - } - - public abstract void runSafely() throws InterruptedException; -} diff --git a/util/src/main/java/com/loadtestgo/util/ThreadNamer.java b/util/src/main/java/com/loadtestgo/util/ThreadNamer.java deleted file mode 100644 index dcbb678..0000000 --- a/util/src/main/java/com/loadtestgo/util/ThreadNamer.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.loadtestgo.util; - -import java.util.concurrent.ThreadFactory; - -public class ThreadNamer implements ThreadFactory { - final private String format; - private int threadNum; - - public ThreadNamer(String format) { - this.format = format; - this.threadNum = 0; - } - - @Override - public Thread newThread(Runnable r) { - synchronized (format) { - threadNum++; - } - return new Thread(r, String.format(format, threadNum)); - } -} diff --git a/util/src/main/java/com/loadtestgo/util/TimeFormat.java b/util/src/main/java/com/loadtestgo/util/TimeFormat.java deleted file mode 100644 index 9666361..0000000 --- a/util/src/main/java/com/loadtestgo/util/TimeFormat.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.loadtestgo.util; - -public class TimeFormat { - static public String secondsToShortTime(long seconds) { - long minute = 60; - long hour = 60 * 60; - long day = 24 * hour; - if (seconds < minute) { - return String.format("%02ds", seconds); - } else if (seconds < hour) { - return String.format("%02dm %02ds", (long)Math.floor(seconds / 60), seconds % 60); - } else if (seconds < day) { - long minutes = (long)Math.floor(seconds/60); - return String.format("%dh %02dm %02ds", (long)Math.floor(minutes / 60), minutes % 60, seconds % 60); - } else { - long days = (long)Math.floor(seconds / day); - long hours = (long)Math.floor((seconds % day) / hour); - long minutes = (long)Math.floor((seconds % hour) / minute); - return String.format("%dd %dh %02dm", days, hours, minutes); - } - } -} diff --git a/util/src/main/java/com/loadtestgo/util/Zip.java b/util/src/main/java/com/loadtestgo/util/Zip.java deleted file mode 100644 index 6a71855..0000000 --- a/util/src/main/java/com/loadtestgo/util/Zip.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.loadtestgo.util; - -import java.io.*; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; - -public class Zip { - public static void zipFiles(File dir, File outputFile) throws IOException { - FileOutputStream outputStream = new FileOutputStream(outputFile); - zipTestFiles(dir, outputStream); - } - - public static void zipTestFiles(File dir, OutputStream outputStream) throws IOException { - String[] entries = dir.list(); - byte[] buffer = new byte[4096]; - - try (ZipOutputStream out = new ZipOutputStream(outputStream)) { - for (String entry : entries) { - File f = new File(dir, entry); - if (f.isDirectory()) { - continue; - } - try (FileInputStream in = new FileInputStream(f)) { - ZipEntry zipEntry = new ZipEntry(entry); - out.putNextEntry(zipEntry); - int bytesRead; - while ((bytesRead = in.read(buffer)) != -1) { - out.write(buffer, 0, bytesRead); - } - } - } - } - } - - public static void unzipTestFiles(File zipFile, File outputDir) throws IOException { - unzipFiles(new FileInputStream(zipFile), outputDir); - } - - public static void unzipFiles(InputStream inputStream, File outputDir) throws IOException { - if (!outputDir.exists()) { - outputDir.mkdir(); - } - try (ZipInputStream zipIn = new ZipInputStream(inputStream)) { - ZipEntry entry = zipIn.getNextEntry(); - while (entry != null) { - File filePath = new File(outputDir, entry.getName()); - if (!entry.isDirectory()) { - extractFile(zipIn, filePath); - } else { - filePath.mkdir(); - } - zipIn.closeEntry(); - entry = zipIn.getNextEntry(); - } - } - } - - public static void extractFile(ZipInputStream zipIn, File filePath) throws IOException { - final int BUFFER_SIZE = 4096; - try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))) { - byte[] bytesIn = new byte[BUFFER_SIZE]; - int read = 0; - while ((read = zipIn.read(bytesIn)) != -1) { - bos.write(bytesIn, 0, read); - } - } - } -} diff --git a/util/src/test/java/com/loadtestgo/util/LongBufferTest.java b/util/src/test/java/com/loadtestgo/util/LongBufferTest.java deleted file mode 100644 index 8bcb8a7..0000000 --- a/util/src/test/java/com/loadtestgo/util/LongBufferTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.loadtestgo.util; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import static org.junit.Assert.assertEquals; - -@RunWith(JUnit4.class) -public class LongBufferTest { - @Test - public void basic() { - LongBuffer buffer = new LongBuffer(4); - - assertEquals(4, buffer.capacity()); - assertEquals(0, buffer.size()); - - buffer.add(1); - assertEquals(1, buffer.size()); - assertEquals(0, buffer.begin()); - - buffer.add(2); - assertEquals(2, buffer.size()); - assertEquals(0, buffer.begin()); - assertEquals(1, buffer.end()); - - buffer.add(3); - assertEquals(3, buffer.size()); - assertEquals(0, buffer.begin()); - assertEquals(2, buffer.end()); - - buffer.add(4); - assertEquals(4, buffer.size()); - assertEquals(0, buffer.begin()); - assertEquals(3, buffer.end()); - - buffer.add(5); - assertEquals(4, buffer.size()); - - assertEquals(1, buffer.begin()); - assertEquals(2, buffer.beginValue()); - - assertEquals(0, buffer.end()); - assertEquals(5, buffer.endValue()); - - buffer.add(6); - assertEquals(4, buffer.size()); - - assertEquals(2, buffer.begin()); - assertEquals(3, buffer.beginValue()); - - assertEquals(1, buffer.end()); - assertEquals(6, buffer.endValue()); - } -}