Skip to content

Commit

Permalink
Merge pull request #59 from RADAR-base/release-0.10.1
Browse files Browse the repository at this point in the history
Release 0.10.1
  • Loading branch information
blootsvoets committed Oct 2, 2018
2 parents 2cd9200 + cfbcfa3 commit 33ff57a
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 44 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {
}
dependencies {
implementation group: 'org.radarcns', name: 'radar-commons', version: '0.10.0'
implementation group: 'org.radarcns', name: 'radar-commons', version: '0.10.1'
}
```

Expand All @@ -26,7 +26,7 @@ repositories {
}
dependencies {
implementation group: 'org.radarcns', name: 'radar-commons-server', version: '0.10.0'
implementation group: 'org.radarcns', name: 'radar-commons-server', version: '0.10.1'
}
```

Expand All @@ -40,7 +40,7 @@ repositories {
}
dependencies {
testImplementation group: 'org.radarcns', name: 'radar-commons-testing', version: '0.10.0'
testImplementation group: 'org.radarcns', name: 'radar-commons-testing', version: '0.10.1'
}
```

Expand All @@ -53,7 +53,7 @@ repositories {
}
dependencies {
runtimeOnly group: 'org.radarcns', name: 'radar-commons-unsafe', version: '0.10.0'
runtimeOnly group: 'org.radarcns', name: 'radar-commons-unsafe', version: '0.10.1'
}
```

Expand All @@ -78,7 +78,7 @@ configurations.all {
}
dependencies {
compile group: 'org.radarcns', name: 'radar-commons', version: '0.10.1-SNAPSHOT', changing: true
compile group: 'org.radarcns', name: 'radar-commons', version: '0.10.2-SNAPSHOT', changing: true
}
```

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ subprojects {
// Configuration //
//---------------------------------------------------------------------------//

version = '0.10.0'
version = '0.10.1'
group = 'org.radarcns'
ext.githubRepoName = 'RADAR-CNS/RADAR-Commons'

ext.slf4jVersion = '1.7.25'
ext.kafkaVersion = '2.0.0'
ext.avroVersion = '1.8.2'
ext.confluentVersion = '5.0.0'
ext.jacksonVersion = '2.9.6'
ext.okhttpVersion = '3.10.0'
ext.jacksonVersion = '2.9.7'
ext.okhttpVersion = '3.11.0'
ext.junitVersion = '4.12'
ext.mockitoVersion = '2.13.0'
ext.hamcrestVersion = '1.3'
ext.codacyVersion = '2.0.1'
ext.radarSchemasVersion = '0.3.4'
ext.radarSchemasVersion = '0.4.0'
ext.orgJsonVersion = '20170516'

ext.githubUrl = 'https://github.com/' + githubRepoName + '.git'
Expand Down
14 changes: 0 additions & 14 deletions radar-commons-unsafe/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,13 @@ pmd {
sourceSets = []
}

jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.enabled false
}
}

task downloadDependencies(type: Exec) {
configurations.testRuntime.files
configurations.codacy.files
configurations.jacocoAnt.files
commandLine 'echo', 'Downloaded all dependencies'
}

task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
main = 'com.codacy.CodacyCoverageReporter'
classpath = configurations.codacy
args = ['-l', 'Java', '-r', "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"]
}

//---------------------------------------------------------------------------//
// Build system metadata //
//---------------------------------------------------------------------------//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public void writeToSink(BufferedSink sink) throws IOException {
binaryEncoder.writeInt(keyVersion);
binaryEncoder.writeInt(valueVersion);

// do not send project ID; it is encoded in the serialization
binaryEncoder.writeIndex(0);
// do not send user ID; it is encoded in the serialization
binaryEncoder.writeIndex(0);
String sourceId = ((IndexedRecord) records.getKey()).get(sourceIdPos).toString();
binaryEncoder.writeString(sourceId);
binaryEncoder.writeArrayStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.apache.avro.SchemaValidationException;
import org.apache.avro.generic.IndexedRecord;
Expand Down Expand Up @@ -174,9 +175,18 @@ private void downgradeConnection(Request request, Response response) throws IOEx
sender.useLegacyEncoding(
KAFKA_REST_ACCEPT_LEGACY_ENCODING, KAFKA_REST_AVRO_LEGACY_ENCODING,
false);
} else {
RequestBody body = request.body();
MediaType contentType = body != null ? body.contentType() : null;
if (contentType == null || contentType.equals(KAFKA_REST_AVRO_LEGACY_ENCODING)) {
throw fail(request, response,
new IOException("Content-Type " + contentType + " not accepted by server."));
} else {
// the connection may have been downgraded already
state.didConnect();
logger.warn("Content-Type changed during request");
}
}

throw fail(request, response, new IOException("Content-Type not accepted"));
}

private Request buildRequest(RestSender.RequestContext context, RecordData<K, V> records)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void rethrow() throws IOException {
if (getCause() instanceof IOException) {
throw (IOException)getCause();
} else {
throw this;
throw new IOException(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + keyClass.hashCode();
result = 31 * result + valueClass.hashCode();
return result;
return Objects.hash(getName(), keyClass, valueClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,41 @@

import static org.junit.Assert.assertArrayEquals;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collections;
import okio.Buffer;
import org.apache.avro.SchemaValidationException;
import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.EncoderFactory;
import org.apache.avro.specific.SpecificDatumWriter;
import org.junit.Test;
import org.radarcns.data.AvroRecordData;
import org.radarcns.kafka.ObservationKey;
import org.radarcns.kafka.RecordSet;
import org.radarcns.passive.empatica.EmpaticaE4BloodVolumePulse;
import org.radarcns.topic.AvroTopic;

public class BinaryRecordRequestTest {

// note that positive numbers are multiplied by two in avro binary encoding, due to the
// zig-zag encoding schema used.
// See http://avro.apache.org/docs/1.8.1/spec.html#binary_encoding
private static final byte[] EXPECTED = {
2, // key version x2
4, // value version x2
0, // null project ID
0, // null user ID
2, (byte)'b', // string length x2, sourceId
2, // number of records x2
40, // number of bytes in the first value x2
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // value
0 // end of array
};

@Test
public void writeToStream() throws SchemaValidationException, IOException {

ObservationKey k = new ObservationKey("test", "a", "b");
EmpaticaE4BloodVolumePulse v = new EmpaticaE4BloodVolumePulse(0.0, 0.0,
0.0f);
Expand All @@ -29,21 +50,29 @@ public void writeToStream() throws SchemaValidationException, IOException {
new ParsedSchemaMetadata(4, 2, v.getSchema()),
new AvroRecordData<>(t, k, Collections.singletonList(v)));

// note that positive numbers are multiplied by two in avro binary encoding, due to the
// zig-zag encoding schema used.
// See http://avro.apache.org/docs/1.8.1/spec.html#binary_encoding
byte[] expected = {
2, // key version x2
4, // value version x2
2, (byte)'b', // string length x2, sourceId
2, // number of records x2
40, // number of bytes in the first value x2
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // value
0 // end of array
};

Buffer buffer = new Buffer();
request.writeToSink(buffer);
assertArrayEquals(expected, buffer.readByteArray());
assertArrayEquals(EXPECTED, buffer.readByteArray());
}

@Test
public void expectedMatchesRecordSet() throws IOException {
RecordSet recordSet = RecordSet.newBuilder()
.setKeySchemaVersion(1)
.setValueSchemaVersion(2)
.setData(Collections.singletonList(ByteBuffer.wrap(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})))
.setProjectId(null)
.setUserId(null)
.setSourceId("b")
.build();

SpecificDatumWriter<RecordSet> writer = new SpecificDatumWriter<>(RecordSet.SCHEMA$);
ByteArrayOutputStream out = new ByteArrayOutputStream();
BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
writer.write(recordSet, encoder);
encoder.flush();

assertArrayEquals(EXPECTED, out.toByteArray());
}
}

0 comments on commit 33ff57a

Please sign in to comment.