-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from RADAR-CNS/dev
Merge dev to master
- Loading branch information
Showing
9 changed files
with
263 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bintrayUser=username | ||
bintrayApiKey=apikey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/org/radarcns/data/SpecificRecordDecorderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
src/test/java/org/radarcns/producer/direct/DirectProducerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |