Skip to content

Commit

Permalink
Removed deprecated calls
Browse files Browse the repository at this point in the history
  • Loading branch information
blootsvoets committed Jun 10, 2020
1 parent 4f8c7a0 commit c3328e7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.radarbase.mock;

import static io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG;
import static io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig.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;
Expand Down Expand Up @@ -193,7 +193,7 @@ private List<KafkaSender> createRestSenders(int numDevices,

/** Start sending data. */
public void start() throws IOException {
for (MockDevice device : devices) {
for (MockDevice<?> device : devices) {
device.start();
}
for (MockFileSender file : files) {
Expand All @@ -205,11 +205,11 @@ public void start() throws IOException {
public void shutdown() throws IOException, InterruptedException, SchemaValidationException {
if (!devices.isEmpty()) {
logger.info("Shutting down mock devices");
for (MockDevice device : devices) {
for (MockDevice<?> device : devices) {
device.shutdown();
}
logger.info("Waiting for mock devices to finish...");
for (MockDevice device : devices) {
for (MockDevice<?> device : devices) {
device.join(5_000L);
}
}
Expand All @@ -218,7 +218,7 @@ public void shutdown() throws IOException, InterruptedException, SchemaValidatio
sender.close();
}

for (MockDevice device : devices) {
for (MockDevice<?> device : devices) {
device.checkException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.radarbase.mock.data;

import static org.junit.Assert.assertThrows;

import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
Expand All @@ -34,8 +36,6 @@ public class MockRecordValidatorTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();

@Rule
public ExpectedException exception = ExpectedException.none();
private Path root;

private MockDataConfig makeConfig() throws IOException {
Expand Down Expand Up @@ -63,7 +63,6 @@ public void validate() throws Exception {
MockDataConfig config = makeConfig();
generator.generate(config, 100_000L, root);

// doesn't throw
new MockRecordValidator(config, 100_000L, root).validate();
}

Expand All @@ -74,8 +73,7 @@ public void validateWrongDuration() throws Exception {
MockDataConfig config = makeConfig();
generator.generate(config, 100_000L, root);

exception.expect(IllegalArgumentException.class);
new MockRecordValidator(config, 10_000L, root).validate();
assertValidateThrows(IllegalArgumentException.class, config);
}

@Test
Expand All @@ -88,7 +86,7 @@ public void validateCustom() throws Exception {
writer.append("test,a,b,1,2,1\n");
}

new MockRecordValidator(config, 2_000L, root).validate();
assertValidate(config);
}

@Test
Expand All @@ -101,8 +99,7 @@ public void validateWrongKey() throws Exception {
writer.append("test,a,c,1,2,1\n");
}

exception.expect(IllegalArgumentException.class);
new MockRecordValidator(config, 2_000L, root).validate();
assertValidateThrows(IllegalArgumentException.class, config);
}

@Test
Expand All @@ -115,8 +112,7 @@ public void validateWrongTime() throws Exception {
writer.append("test,a,b,1,0,1\n");
}

exception.expect(IllegalArgumentException.class);
new MockRecordValidator(config, 2_000L, root).validate();
assertValidateThrows(IllegalArgumentException.class, config);
}


Expand All @@ -130,8 +126,7 @@ public void validateMissingKeyField() throws Exception {
writer.append("test,a,1,2,1\n");
}

exception.expect(NullPointerException.class);
new MockRecordValidator(config, 2_000L, root).validate();
assertValidateThrows(NullPointerException.class, config);
}

@Test
Expand All @@ -144,8 +139,7 @@ public void validateMissingValueField() throws Exception {
writer.append("test,a,b,1,2\n");
}

exception.expect(NullPointerException.class);
new MockRecordValidator(config, 2_000L, root).validate();
assertValidateThrows(NullPointerException.class, config);
}

@Test
Expand All @@ -158,8 +152,7 @@ public void validateMissingValue() throws Exception {
writer.append("test,a,b,1,2,1\n");
}

exception.expect(ArrayIndexOutOfBoundsException.class);
new MockRecordValidator(config, 2_000L, root).validate();
assertValidateThrows(ArrayIndexOutOfBoundsException.class, config);
}

@Test
Expand All @@ -172,8 +165,7 @@ public void validateWrongValueType() throws Exception {
writer.append("test,a,b,1,2,b\n");
}

exception.expect(NumberFormatException.class);
new MockRecordValidator(config, 2_000L, root).validate();
assertValidateThrows(NumberFormatException.class, config);
}

@Test
Expand All @@ -188,6 +180,15 @@ public void validateMultipleFields() throws Exception {
writer.append("test,a,b,1,2,1,1,1\n");
}

assertValidate(config);
}

private <T extends Throwable> void assertValidateThrows(Class<T> ex, MockDataConfig config) {
MockRecordValidator validator = new MockRecordValidator(config, 2_000L, root);
assertThrows(ex, validator::validate);
}

private void assertValidate(MockDataConfig config) {
new MockRecordValidator(config, 2_000L, root).validate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.radarbase.producer.rest;

import static org.radarbase.producer.rest.RestClient.responseBody;
import static org.radarbase.producer.rest.UncheckedRequestException.fail;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.radarbase.producer.rest;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import java.io.IOException;
import java.util.Collections;
Expand All @@ -28,23 +29,17 @@
import org.apache.avro.Schema.Field;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.radarbase.config.ServerConfig;

public class SchemaRetrieverTest {
private MockWebServer server;
private ServerConfig config;
private SchemaRetriever retriever;

@Rule
public ExpectedException exception = ExpectedException.none();

@Before
public void setUp() {
server = new MockWebServer();
config = new ServerConfig();
ServerConfig config = new ServerConfig();
config.setProtocol("http");
config.setHost(server.getHostName());
config.setPort(server.getPort());
Expand All @@ -58,7 +53,7 @@ public void tearDown() throws IOException {
}

@Test
public void subject() throws Exception {
public void subject() {
assertEquals("bla-value", SchemaRetriever.subject("bla", true));
assertEquals("bla-key", SchemaRetriever.subject("bla", false));
}
Expand Down Expand Up @@ -95,16 +90,15 @@ public void getSchemaMetadata() throws Exception {

// Already queried schema is cached and does not need another request
ParsedSchemaMetadata metadata2 = retriever.getSchemaMetadata("bla", true, -1);
assertEquals(Integer.valueOf(10), metadata.getId());
assertEquals(Integer.valueOf(2), metadata.getVersion());
assertEquals(Schema.create(Schema.Type.STRING), metadata.getSchema());
assertEquals(Integer.valueOf(10), metadata2.getId());
assertEquals(Integer.valueOf(2), metadata2.getVersion());
assertEquals(Schema.create(Schema.Type.STRING), metadata2.getSchema());
assertEquals(1, server.getRequestCount());

// Not yet queried schema needs a new request, so if the server does not respond, an
// IOException is thrown.
server.enqueue(new MockResponse().setResponseCode(500));
exception.expect(IOException.class);
retriever.getSchemaMetadata("bla", false, 2);
assertThrows(IOException.class, () -> retriever.getSchemaMetadata("bla", false, 2));
}

@Test
Expand All @@ -122,9 +116,8 @@ public void addSchemaMetadata() throws Exception {
List<Field> schemaFields = Collections.singletonList(
new Field("a", Schema.create(Schema.Type.INT), "that a", 10));

Schema record = Schema.createRecord("C", "that C", "org.radarcns", false);
metadata = new ParsedSchemaMetadata(null, null,
Schema.createRecord("C", "that C", "org.radarcns", false, schemaFields));
Schema record = Schema.createRecord("C", "that C", "org.radarcns", false, schemaFields);
metadata = new ParsedSchemaMetadata(null, null, record);
server.enqueue(new MockResponse().setBody("{\"id\":11}"));
retriever.addSchemaMetadata("bla", true, metadata);
assertEquals(Integer.valueOf(11), metadata.getId());
Expand Down Expand Up @@ -167,4 +160,4 @@ public void getOrSetSchemaMetadataGet() throws Exception {
assertEquals(Integer.valueOf(10), metadata.getId());
assertEquals(Schema.create(Schema.Type.STRING), metadata.getSchema());
}
}
}

0 comments on commit c3328e7

Please sign in to comment.