Skip to content

Commit

Permalink
Merge pull request #19 from RADAR-CNS/v0.4_release
Browse files Browse the repository at this point in the history
V0.4 release
  • Loading branch information
blootsvoets committed May 30, 2017
2 parents 80fefa0 + 3b9f62f commit 93a6c1e
Show file tree
Hide file tree
Showing 29 changed files with 1,062 additions and 611 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {
}
dependencies {
compile group: 'org.radarcns', name: 'radar-commons', version: '0.3'
compile group: 'org.radarcns', name: 'radar-commons', version: '0.4'
}
```

Expand All @@ -26,7 +26,7 @@ repositories {
}
dependencies {
testCompile group: 'org.radarcns', name: 'radar-commons-testing', version: '0.3'
testCompile group: 'org.radarcns', name: 'radar-commons-testing', version: '0.4'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ allprojects {
// Configuration //
//---------------------------------------------------------------------------//

version = '0.3'
version = '0.4'
group = 'org.radarcns'
ext.githubRepoName = 'RADAR-CNS/RADAR-Commons'

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/radarcns/producer/rest/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
import okhttp3.Response;
import org.radarcns.config.ServerConfig;

/** REST client using OkHttp3. */
/** REST client using OkHttp3. This class is not thread-safe. */
public class RestClient implements Closeable {
private final long timeout;
private final ServerConfig config;
private final OkHttpClient httpClient;
private final ManagedConnectionPool connectionPool;
private boolean isClosed;

/**
* REST client. This client will use the OkHttp3 default connection pool and 30 second timeout.
Expand All @@ -68,6 +69,7 @@ public RestClient(ServerConfig config, long connectionTimeout,
this.config = config;
this.timeout = connectionTimeout;
this.connectionPool = connectionPool;
this.isClosed = false;

OkHttpClient.Builder builder;
if (config.isUnsafe()) {
Expand Down Expand Up @@ -247,6 +249,10 @@ public String toString() {

@Override
public void close() {
if (isClosed) {
return;
}
isClosed = true;
if (connectionPool != null) {
connectionPool.release();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void configure(Map<String, ?> configs, boolean isKey) {
public void close() {
if (schemaRetriever != null) {
schemaRetriever.close();
schemaRetriever = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2017 King's College London and The Hyve
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.radarcns.stream.collector;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

/**
* Created by nivethika on 20-12-16.
*/
public class DoubleArrayCollectorTest {

private DoubleArrayCollector arrayCollector;

@Before
public void setUp() {
this.arrayCollector = new DoubleArrayCollector();
}

@Test
public void add() {
double[] arrayvalues = {0.15d, 1.0d, 2.0d, 3.0d};
this.arrayCollector.add(arrayvalues);

assertEquals("[DoubleValueCollector{min=0.15, max=0.15, sum=0.15, count=1.0, avg=0.15, quartile=[0.15, 0.15, 0.15], iqr=0.0, history=[0.15]}, DoubleValueCollector{min=1.0, max=1.0, sum=1.0, count=1.0, avg=1.0, quartile=[1.0, 1.0, 1.0], iqr=0.0, history=[1.0]}, DoubleValueCollector{min=2.0, max=2.0, sum=2.0, count=1.0, avg=2.0, quartile=[2.0, 2.0, 2.0], iqr=0.0, history=[2.0]}, DoubleValueCollector{min=3.0, max=3.0, sum=3.0, count=1.0, avg=3.0, quartile=[3.0, 3.0, 3.0], iqr=0.0, history=[3.0]}]" , this.arrayCollector.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2017 King's College London and The Hyve
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.radarcns.stream.collector;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

/**
* Created by nivethika on 20-12-16.
*/
public class DoubleValueCollectorTest {

private DoubleValueCollector valueCollector ;

@Before
public void setUp() {
this.valueCollector = new DoubleValueCollector();
}

@Test
public void add() {
valueCollector.add(10.0d);
assertEquals(10.0d, valueCollector.getMin(), 0.0d);
assertEquals(10.0d, valueCollector.getMax(), 0.0d);
assertEquals(10.0d, valueCollector.getSum(), 0.0d);
assertEquals(10.0d, valueCollector.getAvg(), 0.0d);
assertEquals(0.0d, valueCollector.getIqr(), 0.0d);
assertEquals(1, valueCollector.getCount(),0);

valueCollector.add(15.100d);
assertEquals(10.0d, valueCollector.getMin(), 0.0d);
assertEquals(15.100d, valueCollector.getMax(), 0.0d);
assertEquals(25.100d, valueCollector.getSum(), 0.0d);
assertEquals(12.550d, valueCollector.getAvg(), 0.0d);
assertEquals(5.1, valueCollector.getIqr(), 0.0d);
assertEquals(2, valueCollector.getCount(),0);

valueCollector.add(28.100d);
assertEquals(18.1d, valueCollector.getIqr(), 0.0d);

}

@Test
public void addFloat() {
valueCollector.add(10.0234f);
assertEquals(10.0234d, valueCollector.getMin(), 0.0d);
assertEquals(10.0234d, valueCollector.getMax(), 0.0d);
assertEquals(10.0234d, valueCollector.getSum(), 0.0d);
assertEquals(10.0234d, valueCollector.getAvg(), 0.0d);
assertEquals(0.0d, valueCollector.getIqr(), 0.0d);
assertEquals(1, valueCollector.getCount(),0);

valueCollector.add(15.0d);
assertEquals(10.0234d, valueCollector.getMin(), 0.0d);
assertEquals(15.0d, valueCollector.getMax(), 0.0d);
assertEquals(25.0234d, valueCollector.getSum(), 0.0d);
assertEquals(12.5117d, valueCollector.getAvg(), 0.0d);
assertEquals(4.9766d, valueCollector.getIqr(), 0.0d);
assertEquals(2, valueCollector.getCount(),0);

valueCollector.add(28.100d);
assertEquals(18.0766d, valueCollector.getIqr(), 0.0d);

}

@Test
public void testAverage() {
double[] input = {36.793899922141186, 36.878288191353626, 36.965575690177715, 36.988087035729855, 36.628622572158214};
for (double d : input) {
valueCollector.add(d);
}
assertEquals(36.850894682312116, valueCollector.getAvg(), 0);
}

@Test
public void testAverageFloat() {
double[] input = {36.793899922141186, 36.878288191353626, 36.965575690177715, 36.988087035729855, 36.628622572158214};
for (double d : input) {
valueCollector.add((float)d);
}
// converting to float will give a lower number of decimals on the double result
assertEquals(36.8508954, valueCollector.getAvg(), 0);
}
}
4 changes: 2 additions & 2 deletions testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ run {
ext.testingName = 'radar-commons-testing'
ext.description = 'RADAR Common testing library mocking code and utilities.'

targetCompatibility = 1.7
sourceCompatibility = 1.7
targetCompatibility = '1.7'
sourceCompatibility = '1.7'

dependencies {
api rootProject
Expand Down

This file was deleted.

Loading

0 comments on commit 93a6c1e

Please sign in to comment.