Skip to content

Commit

Permalink
Merge pull request #5 from RADAR-CNS/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
nivemaham authored Feb 27, 2017
2 parents 963a387 + d300eb0 commit e95aeb2
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 74 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@ before_install:
- ./gradlew downloadDependencies
after_script:
- ./gradlew sendCoverageToCodacy

deploy:
provider: releases
api_key:
secure: ${GH_TOKEN}
file:
- build/libs/RADAR-Commons-${TRAVIS_TAG}.jar
- build/libs/RADAR-Commons-${TRAVIS_TAG}-javadoc.jar
- build/libs/RADAR-Commons-${TRAVIS_TAG}-sources.jar
skip_cleanup: true
on:
tags: true

after_deploy:
- ./gradlew bintrayUpload
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# RADAR-Commons
[![Build Status](https://travis-ci.org/RADAR-CNS/RADAR-Commons.svg?branch=master)](https://travis-ci.org/RADAR-CNS/RADAR-Commons)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9fe7a419c83e4798af671e468c7e91cf)](https://www.codacy.com/app/RADAR-CNS/RADAR-Commons?utm_source=github.com&utm_medium=referral&utm_content=RADAR-CNS/RADAR-Commons&utm_campaign=Badge_Grade)

Common utilities library containing basic schemas, streaming features, testing bridges and utils.

Expand Down
77 changes: 76 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ plugins {
id 'com.commercehub.gradle.plugin.avro-base' version '0.9.0'
id 'jacoco'
id 'pmd'
id "com.jfrog.bintray" version "1.7.3"
id 'maven-publish'
}

//---------------------------------------------------------------------------//
// Configuration //
//---------------------------------------------------------------------------//

version = '0.1-SNAPSHOT'
version = 'v0.1-alpha.2'

targetCompatibility = '1.7'
sourceCompatibility = '1.7'
Expand Down Expand Up @@ -174,6 +176,79 @@ task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
args = ['-l', 'Java', '-r', "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"]
}

def pomConfig = {
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "pre-release"
}
}
developers {
developer {
id "radar-cns"
name "Nivethika"
email "nivethika@thehyve.nl"
}
}
}
// custom tasks for creating source/javadoc jars
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.output
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

// add javadoc/source jar tasks as artifacts
artifacts {
archives sourcesJar, javadocJar
}


publishing {
publications {
RadarCommonsPublication(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
groupId 'org.radarcns'
artifactId 'RADAR-Commons'
version System.getenv('TRAVIS_TAG')
pom.withXml {
def root = asNode()
root.appendNode('description', 'Common utilities library containing basic schemas, streaming features, testing bridges and utils.')
root.appendNode('name', 'RADAR-Commons')
root.appendNode('url', 'https://github.com/RADAR-CNS/RADAR-Commons.git')
root.children().last() + pomConfig
}
}
}
}



bintray {
user = System.getenv('bintrayUser')? System.getenv('bintrayUser') : project.property('bintrayUser')
key = System.getenv('bintrayApiKey') ? System.getenv('bintrayApiKey') : project.property('bintrayApiKey')
override = false
publications = ['RadarCommonsPublication']
pkg {
repo = 'org.radarcns'
name = 'RADAR-Commons'
userOrg = 'radar-cns'
licenses = ['Apache-2.0']
vcsUrl = 'https://github.com/RADAR-CNS/RADAR-Commons.git'
version {
name = System.getenv('TRAVIS_TAG')
desc = 'RADAR-Commons unitilies: Initial snapshot'
vcsTag = System.getenv('TRAVIS_TAG')
}
}
}

task wrapper(type: Wrapper) {
gradleVersion = '3.2.1'
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bintrayUser=username
bintrayApiKey=apikey
13 changes: 13 additions & 0 deletions src/main/java/org/radarcns/data/TimedInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@ public void set(int value) {
this.value.set(value);
time.set(System.currentTimeMillis());
}

public synchronized boolean equals(Object other) {
if (other == null || !getClass().equals(other.getClass())) {
return false;
}
TimedInt timedOther = (TimedInt)other;
return value.equals(timedOther.value) && time.equals(timedOther.time);
}

@Override
public int hashCode() {
return 31 * value.hashCode() + time.hashCode();
}
}
53 changes: 53 additions & 0 deletions src/test/java/org/radarcns/data/SpecificRecordDecorderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.radarcns.data;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import org.junit.Test;
import org.radarcns.empatica.EmpaticaE4BloodVolumePulse;
import org.radarcns.key.MeasurementKey;
import org.radarcns.topic.AvroTopic;

/**
* Created by nivethika on 24-2-17.
*/
public class SpecificRecordDecorderTest {

@Test
public void decordJson() throws IOException {
SpecificRecordDecoder decoder = new SpecificRecordDecoder(false);
AvroTopic<MeasurementKey, EmpaticaE4BloodVolumePulse> topic = new AvroTopic<>("keeeeys", MeasurementKey.getClassSchema(), EmpaticaE4BloodVolumePulse.getClassSchema(), MeasurementKey.class, EmpaticaE4BloodVolumePulse.class);
AvroDecoder.AvroReader<MeasurementKey> keyDecoder = decoder.reader(topic.getKeySchema(), topic.getKeyClass());
AvroDecoder.AvroReader<EmpaticaE4BloodVolumePulse> valueDecoder = decoder.reader(topic.getValueSchema(), topic.getValueClass());

MeasurementKey key = keyDecoder.decode("{\"userId\":\"a\",\"sourceId\":\"b\"}".getBytes());
assertEquals(key.get("userId"), "a");
assertEquals(key.get("sourceId"), "b");

EmpaticaE4BloodVolumePulse value = valueDecoder.decode("{\"time\":0.0,\"timeReceived\":0.0,\"bloodVolumePulse\":0.0}".getBytes());
assertEquals(value.get("time"), 0.0d);
assertEquals(value.get("timeReceived"), 0.0d);
assertEquals(value.get("bloodVolumePulse"), 0.0f);
}

@Test
public void decordBinary() throws IOException {

SpecificRecordDecoder decoder = new SpecificRecordDecoder(true);
AvroTopic<MeasurementKey, EmpaticaE4BloodVolumePulse> topic = new AvroTopic<>("keeeeys", MeasurementKey.getClassSchema(), EmpaticaE4BloodVolumePulse.getClassSchema(), MeasurementKey.class, EmpaticaE4BloodVolumePulse.class);
AvroDecoder.AvroReader<MeasurementKey> keyDecoder = decoder.reader(topic.getKeySchema(), topic.getKeyClass());
AvroDecoder.AvroReader<EmpaticaE4BloodVolumePulse> valueDecoder = decoder.reader(topic.getValueSchema(), topic.getValueClass());

byte[] inputKey = {2, 97, 2, 98};
MeasurementKey key = keyDecoder.decode( inputKey);
assertEquals(key.get("userId"), "a");
assertEquals(key.get("sourceId"), "b");

byte[] inputValue = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

EmpaticaE4BloodVolumePulse value = valueDecoder.decode(inputValue);
assertEquals(value.get("time"), 0.0d);
assertEquals(value.get("timeReceived"), 0.0d);
assertEquals(value.get("bloodVolumePulse"), 0.0f);
}
}
28 changes: 28 additions & 0 deletions src/test/java/org/radarcns/data/StringEncoderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.radarcns.data;

import static org.junit.Assert.assertTrue;

import java.io.IOException;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Type;
import org.junit.Test;

/**
* Created by nivethika on 24-2-17.
*/
public class StringEncoderTest {

@Test
public void encodeString() throws IOException {
StringEncoder encoder = new StringEncoder();
Schema schema = Schema.create(Type.STRING);

AvroEncoder.AvroWriter<String> keyEncoder = encoder.writer(schema, String.class);


byte[] key = keyEncoder.encode("{\"userId\":\"a\",\"sourceId\":\"b\"}");
assertTrue( new String(key).contains("userId"));
assertTrue( new String(key).contains("sourceId"));
}

}
73 changes: 0 additions & 73 deletions src/test/java/org/radarcns/kafka/DirectProducerTest.java

This file was deleted.

75 changes: 75 additions & 0 deletions src/test/java/org/radarcns/producer/direct/DirectProducerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.radarcns.producer.direct;

import static io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG;
import static org.apache.kafka.clients.producer.ProducerConfig.BOOTSTRAP_SERVERS_CONFIG;
import static org.apache.kafka.clients.producer.ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG;
import static org.apache.kafka.clients.producer.ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG;

import io.confluent.kafka.serializers.KafkaAvroSerializer;
import junit.framework.TestCase;

import org.radarcns.key.MeasurementKey;
import org.radarcns.mock.MockDevice;
import org.radarcns.producer.KafkaSender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Properties;

public class DirectProducerTest extends TestCase {

private static final Logger logger = LoggerFactory.getLogger(DirectProducerTest.class);

public void testDirect() throws InterruptedException, IOException {

Properties props = new Properties();
props.put(KEY_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
props.put(VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
props
.put(SCHEMA_REGISTRY_URL_CONFIG, "http://localhost:8081");
props.put(BOOTSTRAP_SERVERS_CONFIG, "http://localhost:9092");

if (!Boolean.parseBoolean(props.getProperty("servertest","false"))) {
logger.info("Serve test case has been disable.");
return;
}

int numberOfDevices = 1;
logger.info("Simulating the load of " + numberOfDevices);

String userID = "UserID_";
String sourceID = "SourceID_";

MockDevice[] threads = new MockDevice[numberOfDevices];
KafkaSender[] senders = new KafkaSender[numberOfDevices];
for (int i = 0; i < numberOfDevices; i++) {
senders[i] = new DirectSender(props);
//noinspection unchecked
threads[i] = new MockDevice<>(senders[i], new MeasurementKey(userID+i, sourceID+i), MeasurementKey.getClassSchema(), MeasurementKey.class);
threads[i].start();
}
long streamingTimeoutMs = 5_000L;
if (props.containsKey("streaming.timeout.ms")) {
try {
streamingTimeoutMs = Long.parseLong(props.getProperty("streaming.timeout.ms"));
} catch (NumberFormatException ex) {
// whatever
}
}
threads[0].join(streamingTimeoutMs);
for (MockDevice device : threads) {
device.interrupt();
}
for (MockDevice device : threads) {
device.join();
}
for (KafkaSender sender : senders) {
try {
sender.close();
} catch (IOException e) {
logger.warn("Failed to close sender", e);
}
}
}
}

0 comments on commit e95aeb2

Please sign in to comment.