Skip to content

Commit

Permalink
Merge pull request #236 from RADAR-base/release-0.5.11.1
Browse files Browse the repository at this point in the history
Release 0.5.11.1
  • Loading branch information
blootsvoets authored Jul 23, 2020
2 parents 157002c + 94cd18b commit 88e299d
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 5 deletions.
4 changes: 2 additions & 2 deletions java-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ repositories {
dependencies {
// Commons schemas (backend, passive remote monitoring app)
compile 'org.radarcns:radar-schemas-commons:0.5.10'
compile 'org.radarcns:radar-schemas-commons:0.5.11.1'
// Questionnaire schemas (active remote monitoring app)
compile 'org.radarcns:radar-schemas-tools:0.5.10'
compile 'org.radarcns:radar-schemas-tools:0.5.11.1'
}
```
Usually, you only need to include the schemas you actually need in your dependencies.
Expand Down
2 changes: 1 addition & 1 deletion java-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ subprojects {
apply plugin: 'idea'

// Configuration
version = '0.5.11'
version = '0.5.11.1'
group = 'org.radarcns'
ext.githubRepoName = 'RADAR-base/RADAR-Schemas'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ public SourceCatalogueServer(int serverPort) {
this.server = new Server(serverPort);
}

@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void stop() throws Exception {
this.server.stop();
}

@Override
public void close() {
try {
this.server.join();
} catch (InterruptedException e) {
} catch (Exception e) {
logger.error("Cannot stop server", e);
}
server.destroy();
}

@SuppressWarnings("PMD.SignatureDeclareThrowsException")
private void start(SourceCatalogue sourceCatalogue) throws Exception {
public void start(SourceCatalogue sourceCatalogue) throws Exception {
ResourceConfig config = new ResourceConfig();
config.register(new SourceCatalogueService(sourceCatalogue));
ServletHolder servlet = new ServletHolder(new ServletContainer(config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.radarcns.schema.util.SchemaUtils.applyOrEmpty;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -59,10 +60,12 @@ public Map<String, String> getProperties() {
return properties;
}

@JsonIgnore
public Stream<String> getTopicNames() {
return getData().stream().flatMap(DataTopic::getTopicNames);
}

@JsonIgnore
public Stream<AvroTopic<?, ?>> getTopics() {
return getData().stream().flatMap(applyOrEmpty(DataTopic::getTopics));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.WRITE_DOC_START_MARKER;
import static org.radarcns.schema.util.SchemaUtils.expandClass;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -54,11 +55,13 @@ public DataTopic() {
}

/** Get all topic names that are provided by the data. */
@JsonIgnore
public Stream<String> getTopicNames() {
return Stream.of(getTopic());
}

/** Get all Avro topics that are provided by the data. */
@JsonIgnore
public Stream<AvroTopic<?, ?>> getTopics() throws IOException {
try {
return Stream.of(parseAvroTopic());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.radarcns.schema.util.SchemaUtils.applyOrEmpty;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import java.util.ArrayList;
Expand Down Expand Up @@ -93,6 +94,7 @@ public String getTopicBase() {
return topicBase;
}

@JsonIgnore
@Override
public Stream<String> getTopicNames() {
if (windowed) {
Expand All @@ -108,6 +110,7 @@ public Stream<String> getTopicNames() {
}
}

@JsonIgnore
@Override
public Stream<AvroTopic<?, ?>> getTopics() {
return getTopicNames()
Expand All @@ -121,6 +124,7 @@ public Stream<String> getTopicNames() {
}

/** Get only topic names that are used with the fixed time windows. */
@JsonIgnore
public Stream<String> getTimedTopicNames() {
if (windowed) {
return getTopicNames();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.radarcns.schema.specification.stream;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.stream.Stream;
Expand Down Expand Up @@ -34,6 +35,7 @@ public Scope getScope() {
}

/** Get only the topic names that are the output of a timed stream. */
@JsonIgnore
public Stream<String> getTimedTopicNames() {
return data.stream().flatMap(StreamDataTopic::getTimedTopicNames);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.radarcns.schema.service;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.nio.file.Paths;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
import org.radarcns.schema.specification.SourceCatalogue;

public class SourceCatalogueServerTest {
@Rule
public ErrorCollector errorCollector = new ErrorCollector();
private SourceCatalogueServer server;
private Thread serverThread;

@Before
public void setUp() {
server = new SourceCatalogueServer(9876);
serverThread = new Thread(() -> {
try {
SourceCatalogue sourceCatalog = SourceCatalogue.load(Paths.get("../.."));
server.start(sourceCatalog);
server.close();
} catch (InterruptedException | IllegalStateException e) {
// this is acceptable
} catch (Exception e) {
errorCollector.addError(e);
}
});
serverThread.start();
}

@After
public void tearDown() throws Exception {
server.stop();
serverThread.join();
}

@Test
public void sourceTypesTest() throws IOException, InterruptedException {
Thread.sleep(5000L);

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://localhost:9876/source-types")
.build();

try (Response response = client.newCall(request).execute()) {
assertTrue(response.isSuccessful());
ResponseBody body = response.body();
assertNotNull(body);
JsonNode node = new ObjectMapper().readTree(body.byteStream());
assertTrue(node.isObject());
assertTrue(node.has("passive-source-types"));
assertTrue(node.get("passive-source-types").isArray());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
package org.radarcns.schema.validation;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.radarcns.schema.specification.SourceCatalogue.BASE_PATH;
import static org.radarcns.schema.validation.ValidationHelper.isValidTopic;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
import org.radarcns.schema.specification.DataProducer;
import org.radarcns.schema.specification.SourceCatalogue;

Expand All @@ -37,6 +41,9 @@
public class SourceCatalogueValidation {
private static SourceCatalogue catalogue;

@Rule
public ErrorCollector errorCollector = new ErrorCollector();

@BeforeClass
public static void setUp() throws IOException {
catalogue = SourceCatalogue.load(BASE_PATH);
Expand Down Expand Up @@ -76,4 +83,19 @@ public void validateTopicSchemas() {
}
});
}

@Test
public void validateSerialization() {
ObjectMapper mapper = new ObjectMapper();
catalogue.getSources()
.forEach(source -> {
try {
String json = mapper.writeValueAsString(source);
assertFalse(json.contains("\"parallel\":false"));
} catch (Exception ex) {
errorCollector.addError(new IllegalArgumentException(
"Source " + source + " is not valid", ex));
}
});
}
}

0 comments on commit 88e299d

Please sign in to comment.