Skip to content

Commit

Permalink
Merge pull request #63 from RADAR-base/release-0.11.2
Browse files Browse the repository at this point in the history
Release 0.11.2
  • Loading branch information
blootsvoets committed Nov 1, 2018
2 parents 7af4735 + ab39d02 commit 99dc7f4
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 20 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.11.1'
implementation group: 'org.radarcns', name: 'radar-commons', version: '0.11.2'
}
```

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

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

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

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

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

version = '0.11.1'
version = '0.11.2'
group = 'org.radarcns'
ext.githubRepoName = 'RADAR-CNS/RADAR-Commons'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public BinaryRecordRequest(AvroTopic<K, V> topic) throws SchemaValidationExcepti

@Override
public void writeToSink(BufferedSink sink) throws IOException {
writeToSink(sink, Integer.MAX_VALUE);
}

private void writeToSink(BufferedSink sink, int maxLength) throws IOException {
binaryEncoder = EncoderFactory.get().directBinaryEncoder(
sink.outputStream(), binaryEncoder);
binaryEncoder.startItem();
Expand All @@ -88,9 +92,16 @@ public void writeToSink(BufferedSink sink) throws IOException {
binaryEncoder.writeArrayStart();
binaryEncoder.setItemCount(records.size());

int curLength = 18 + sourceId.length();

for (V record : records) {
if (curLength >= maxLength) {
return;
}
binaryEncoder.startItem();
binaryEncoder.writeBytes(valueEncoder.encode(record));
byte[] valueBytes = valueEncoder.encode(record);
binaryEncoder.writeBytes(valueBytes);
curLength += 4 + valueBytes.length;
}
binaryEncoder.writeArrayEnd();
binaryEncoder.flush();
Expand All @@ -113,9 +124,9 @@ public void prepare(ParsedSchemaMetadata keySchema, ParsedSchemaMetadata valueSc
}

@Override
public String content() throws IOException {
public String content(int maxLength) throws IOException {
Buffer buffer = new Buffer();
writeToSink(buffer);
return "0x" + bytesToHex(buffer.readByteArray());
writeToSink(buffer, maxLength / 2 - 2);
return "0x" + bytesToHex(buffer.readByteArray(maxLength - 2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.radarcns.util.Strings.utf8;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import okio.Buffer;
import okio.BufferedSink;
import org.apache.avro.SchemaValidationException;
Expand Down Expand Up @@ -65,6 +66,10 @@ public JsonRecordRequest(AvroTopic<K, V> topic) {
*/
@Override
public void writeToSink(BufferedSink sink) throws IOException {
writeToSink(sink, Integer.MAX_VALUE);
}

private void writeToSink(BufferedSink sink, int maxLength) throws IOException {
sink.writeByte('{');
sink.write(KEY_SCHEMA_ID);
sink.write(utf8(String.valueOf(keyEncoder.getReaderSchema().getId())));
Expand All @@ -75,8 +80,13 @@ public void writeToSink(BufferedSink sink) throws IOException {

byte[] key = keyEncoder.encode(records.getKey());

int curLength = KEY_SCHEMA_ID.length + VALUE_SCHEMA_ID.length + 7;

boolean first = true;
for (V record : records) {
if (curLength >= maxLength) {
return;
}
if (first) {
first = false;
} else {
Expand All @@ -86,8 +96,10 @@ public void writeToSink(BufferedSink sink) throws IOException {
sink.write(key);

sink.write(VALUE);
sink.write(valueEncoder.encode(record));
byte[] valueBytes = valueEncoder.encode(record);
sink.write(valueBytes);
sink.writeByte('}');
curLength += 2 + key.length + KEY.length + VALUE.length + valueBytes.length;
}
sink.write(END);
}
Expand All @@ -106,9 +118,9 @@ public void prepare(ParsedSchemaMetadata keySchema, ParsedSchemaMetadata valueSc
}

@Override
public String content() throws IOException {
public String content(int maxLength) throws IOException {
Buffer buffer = new Buffer();
writeToSink(buffer);
return buffer.readUtf8();
writeToSink(buffer, maxLength);
return buffer.readString(maxLength, StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ void prepare(ParsedSchemaMetadata keySchema, ParsedSchemaMetadata valueSchema,
/**
* Return the content of the record as a string. To avoid dual reading of data for RecordData
* that does not store the results, prepare and reset may be called around this method.
* @param maxLength maximum returned length
* @return the content.
* @throws IOException if the content cannot be written.
*/
String content() throws IOException;
String content(int maxLength) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public void writeTo(BufferedSink sink) throws IOException {
data.writeToSink(sink);
}

static String topicRequestContent(Request request) throws IOException {
static String topicRequestContent(Request request, int maxLength) throws IOException {
TopicRequestBody body = (TopicRequestBody) request.body();
if (body == null) {
return null;
}
return body.data.content();
return body.data.content(maxLength);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ public static UncheckedRequestException fail(Request request,
content = null;
}

String requestContent = topicRequestContent(request);
String requestContent = topicRequestContent(request, LOG_CONTENT_LENGTH);
if (requestContent != null || content != null) {
message.append(':');
}

if (requestContent != null) {
message.append("\n ")
.append(requestContent, 0,
Math.min(requestContent.length(), LOG_CONTENT_LENGTH));
.append(requestContent);
}

if (content != null) {
Expand Down

0 comments on commit 99dc7f4

Please sign in to comment.