Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
package org.apache.druid.common.utils;

import org.apache.druid.java.util.common.StringUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -47,7 +47,7 @@ public class SerializerUtilsTest
private byte[] longsByte;
private ByteArrayOutputStream outStream;

@Before
@BeforeEach
public void setUpByteArrays() throws IOException
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down Expand Up @@ -97,15 +97,15 @@ public void testWriteInts() throws IOException
{
serializerUtils.writeInts(outStream, ints);
byte[] actuals = outStream.toByteArray();
Assert.assertArrayEquals(intsByte, actuals);
Assertions.assertArrayEquals(intsByte, actuals);
}

@Test
public void testWriteFloats() throws IOException
{
serializerUtils.writeFloats(outStream, floats);
byte[] actuals = outStream.toByteArray();
Assert.assertArrayEquals(floatsByte, actuals);
Assertions.assertArrayEquals(floatsByte, actuals);
}

@Test
Expand All @@ -120,15 +120,15 @@ public void testChannelWritefloat() throws IOException
}
float expected = serializerUtils.readFloat(inputstream);
float actuals = floats[index];
Assert.assertEquals(expected, actuals, delta);
Assertions.assertEquals(expected, actuals, delta);
}

@Test
public void testWriteLongs() throws IOException
{
serializerUtils.writeLongs(outStream, longs);
byte[] actuals = outStream.toByteArray();
Assert.assertArrayEquals(longsByte, actuals);
Assertions.assertArrayEquals(longsByte, actuals);
}

@Test
Expand All @@ -142,7 +142,7 @@ public void testChannelWritelong() throws IOException
inputstream.close();
long expected = serializerUtils.readLong(inputstream);
long actuals = longs[index];
Assert.assertEquals(expected, actuals);
Assertions.assertEquals(expected, actuals);
}

@Test
Expand All @@ -151,7 +151,7 @@ public void testReadInts() throws IOException
ByteArrayInputStream inputstream = new ByteArrayInputStream(intsByte);
int[] actuals = serializerUtils.readInts(inputstream);
inputstream.close();
Assert.assertArrayEquals(ints, actuals);
Assertions.assertArrayEquals(ints, actuals);
}

@Test
Expand All @@ -160,7 +160,7 @@ public void testReadFloats() throws IOException
ByteArrayInputStream inputstream = new ByteArrayInputStream(floatsByte);
float[] actuals = serializerUtils.readFloats(inputstream);
inputstream.close();
Assert.assertArrayEquals(floats, actuals, delta);
Assertions.assertArrayEquals(floats, actuals, delta);
}

@Test
Expand All @@ -169,7 +169,7 @@ public void testReadLongs() throws IOException
ByteArrayInputStream inputstream = new ByteArrayInputStream(longsByte);
long[] actuals = serializerUtils.readLongs(inputstream);
inputstream.close();
Assert.assertArrayEquals(longs, actuals);
Assertions.assertArrayEquals(longs, actuals);
}

@Test
Expand All @@ -178,7 +178,7 @@ public void testReadStrings() throws IOException
ByteArrayInputStream inputstream = new ByteArrayInputStream(stringsByte);
String[] actuals = serializerUtils.readStrings(inputstream);
inputstream.close();
Assert.assertArrayEquals(strings, actuals);
Assertions.assertArrayEquals(strings, actuals);
}

@Test
Expand All @@ -192,7 +192,7 @@ public void testChannelWriteString() throws IOException
inputstream.close();
String expected = serializerUtils.readString(inputstream);
String actuals = strings[index];
Assert.assertEquals(expected, actuals);
Assertions.assertEquals(expected, actuals);
}

@Test
Expand All @@ -202,10 +202,10 @@ public void testByteBufferReadStrings()
buffer.put(stringsByte);
buffer.flip();
String[] actuals = serializerUtils.readStrings(buffer);
Assert.assertArrayEquals(strings, actuals);
Assertions.assertArrayEquals(strings, actuals);
}

@After
@AfterEach
public void tearDown() throws IOException
{
serializerUtils = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,23 @@
import org.apache.druid.utils.CompressionUtils;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.matchers.ThrowableMessageMatcher;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Collections;

public class CsvInputFormatTest extends InitializedNullHandlingTest
{
@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
public void testSerde() throws IOException
{
final ObjectMapper mapper = new ObjectMapper();
final CsvInputFormat format = new CsvInputFormat(Collections.singletonList("a"), "|", null, true, 10, null);
final byte[] bytes = mapper.writeValueAsBytes(format);
final CsvInputFormat fromJson = (CsvInputFormat) mapper.readValue(bytes, InputFormat.class);
Assert.assertEquals(format, fromJson);
Assertions.assertEquals(format, fromJson);
}

@Test
Expand All @@ -58,7 +53,7 @@ public void testDeserializeWithoutColumnsWithHasHeaderRow() throws IOException
"{\"type\":\"csv\",\"hasHeaderRow\":true}",
InputFormat.class
);
Assert.assertTrue(inputFormat.isFindColumnsFromHeader());
Assertions.assertTrue(inputFormat.isFindColumnsFromHeader());
}

@Test
Expand All @@ -69,14 +64,14 @@ public void testDeserializeWithoutColumnsWithFindColumnsFromHeaderTrue() throws
"{\"type\":\"csv\",\"findColumnsFromHeader\":true}",
InputFormat.class
);
Assert.assertTrue(inputFormat.isFindColumnsFromHeader());
Assertions.assertTrue(inputFormat.isFindColumnsFromHeader());
}

@Test
public void testDeserializeWithoutColumnsWithFindColumnsFromHeaderFalse()
{
final ObjectMapper mapper = new ObjectMapper();
final JsonProcessingException e = Assert.assertThrows(
final JsonProcessingException e = Assertions.assertThrows(
JsonProcessingException.class,
() -> mapper.readValue(
"{\"type\":\"csv\",\"findColumnsFromHeader\":false}",
Expand All @@ -96,7 +91,7 @@ public void testDeserializeWithoutColumnsWithFindColumnsFromHeaderFalse()
public void testDeserializeWithoutColumnsWithBothHeaderProperties()
{
final ObjectMapper mapper = new ObjectMapper();
final JsonProcessingException e = Assert.assertThrows(
final JsonProcessingException e = Assertions.assertThrows(
JsonProcessingException.class,
() -> mapper.readValue(
"{\"type\":\"csv\",\"findColumnsFromHeader\":true,\"hasHeaderRow\":true}",
Expand All @@ -115,7 +110,7 @@ public void testDeserializeWithoutColumnsWithBothHeaderProperties()
public void testDeserializeWithoutAnyProperties()
{
final ObjectMapper mapper = new ObjectMapper();
final JsonProcessingException e = Assert.assertThrows(
final JsonProcessingException e = Assertions.assertThrows(
JsonProcessingException.class,
() -> mapper.readValue("{\"type\":\"csv\"}", InputFormat.class)
);
Expand All @@ -135,83 +130,91 @@ public void testDeserializeWithTryParseNumbers() throws IOException
"{\"type\":\"csv\",\"hasHeaderRow\":true,\"tryParseNumbers\":true}",
InputFormat.class
);
Assert.assertTrue(inputFormat.shouldTryParseNumbers());
Assertions.assertTrue(inputFormat.shouldTryParseNumbers());
}

@Test
public void testComma()
{
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Column[a,] cannot have the delimiter[,] in its name");
new CsvInputFormat(Collections.singletonList("a,"), "|", null, false, 0, null);
IllegalArgumentException e = Assertions.assertThrows(
IllegalArgumentException.class,
() -> new CsvInputFormat(Collections.singletonList("a,"), "|", null, false, 0, null)
);
Assertions.assertTrue(e.getMessage().contains("Column[a,] cannot have the delimiter[,] in its name"));
}

@Test
public void testDelimiter()
{
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Cannot have same delimiter and list delimiter of [,]");
new CsvInputFormat(Collections.singletonList("a\t"), ",", null, false, 0, null);
IllegalArgumentException e = Assertions.assertThrows(
IllegalArgumentException.class,
() -> new CsvInputFormat(Collections.singletonList("a\t"), ",", null, false, 0, null)
);
Assertions.assertTrue(e.getMessage().contains("Cannot have same delimiter and list delimiter of [,]"));
}

@Test
public void testFindColumnsFromHeaderWithColumnsReturningItsValue()
{
final CsvInputFormat format = new CsvInputFormat(Collections.singletonList("a"), null, null, true, 0, null);
Assert.assertTrue(format.isFindColumnsFromHeader());
Assertions.assertTrue(format.isFindColumnsFromHeader());
}

@Test
public void testFindColumnsFromHeaderWithMissingColumnsReturningItsValue()
{
final CsvInputFormat format = new CsvInputFormat(null, null, null, true, 0, null);
Assert.assertTrue(format.isFindColumnsFromHeader());
Assertions.assertTrue(format.isFindColumnsFromHeader());
}

@Test
public void testMissingFindColumnsFromHeaderWithMissingColumnsThrowingError()
{
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Either [columns] or [findColumnsFromHeader] must be set");
new CsvInputFormat(null, null, null, null, 0, null);
IllegalArgumentException e = Assertions.assertThrows(
IllegalArgumentException.class,
() -> new CsvInputFormat(null, null, null, null, 0, null)
);
Assertions.assertTrue(e.getMessage().contains("Either [columns] or [findColumnsFromHeader] must be set"));
}

@Test
public void testMissingFindColumnsFromHeaderWithColumnsReturningFalse()
{
final CsvInputFormat format = new CsvInputFormat(Collections.singletonList("a"), null, null, null, 0, null);
Assert.assertFalse(format.isFindColumnsFromHeader());
Assertions.assertFalse(format.isFindColumnsFromHeader());
}

@Test
public void testHasHeaderRowWithMissingFindColumnsThrowingError()
{
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Cannot accept both [findColumnsFromHeader] and [hasHeaderRow]");
new CsvInputFormat(null, null, true, false, 0, null);
IllegalArgumentException e = Assertions.assertThrows(
IllegalArgumentException.class,
() -> new CsvInputFormat(null, null, true, false, 0, null)
);
Assertions.assertTrue(e.getMessage().contains("Cannot accept both [findColumnsFromHeader] and [hasHeaderRow]"));
}

@Test
public void testHasHeaderRowWithMissingColumnsReturningItsValue()
{
final CsvInputFormat format = new CsvInputFormat(null, null, true, null, 0, null);
Assert.assertTrue(format.isFindColumnsFromHeader());
Assertions.assertTrue(format.isFindColumnsFromHeader());
}

@Test
public void test_getWeightedSize_withoutCompression()
{
final CsvInputFormat format = new CsvInputFormat(null, null, true, null, 0, null);
final long unweightedSize = 100L;
Assert.assertEquals(unweightedSize, format.getWeightedSize("file.csv", unweightedSize));
Assertions.assertEquals(unweightedSize, format.getWeightedSize("file.csv", unweightedSize));
}

@Test
public void test_getWeightedSize_withGzCompression()
{
final CsvInputFormat format = new CsvInputFormat(null, null, true, null, 0, null);
final long unweightedSize = 100L;
Assert.assertEquals(
Assertions.assertEquals(
unweightedSize * CompressionUtils.COMPRESSED_TEXT_WEIGHT_FACTOR,
format.getWeightedSize("file.csv.gz", unweightedSize)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
import com.sun.net.httpserver.HttpServer;
import org.apache.commons.io.IOUtils;
import org.apache.druid.java.util.common.StringUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.AdditionalAnswers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
Expand All @@ -54,7 +52,7 @@ public class HttpEntityTest
private URLConnection urlConnection;
private InputStream inputStreamMock;

@Before
@BeforeEach
public void setup() throws IOException
{
uri = Mockito.mock(URI.class);
Expand All @@ -67,9 +65,6 @@ public void setup() throws IOException
Mockito.when(inputStreamMock.skip(ArgumentMatchers.anyLong())).then(AdditionalAnswers.returnsFirstArg());
}

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

@Test
public void testOpenInputStream() throws IOException, URISyntaxException
{
Expand Down Expand Up @@ -103,7 +98,7 @@ public void testOpenInputStream() throws IOException, URISyntaxException
inputStream = HttpEntity.openInputStream(url, "", null, 0, Collections.emptyMap());
inputStreamPartial = HttpEntity.openInputStream(url, "", null, 5, Collections.emptyMap());
inputStream.skip(5);
Assert.assertTrue(IOUtils.contentEquals(inputStream, inputStreamPartial));
Assertions.assertTrue(IOUtils.contentEquals(inputStream, inputStreamPartial));
}
finally {
IOUtils.closeQuietly(inputStream);
Expand Down Expand Up @@ -136,8 +131,8 @@ public void testRequestHeaders() throws IOException, URISyntaxException
(httpExchange) -> {
Headers headers = httpExchange.getRequestHeaders();
for (Map.Entry<String, String> entry : requestHeaders.entrySet()) {
Assert.assertTrue(headers.containsKey(entry.getKey()));
Assert.assertEquals(headers.get(entry.getKey()).get(0), entry.getValue());
Assertions.assertTrue(headers.containsKey(entry.getKey()));
Assertions.assertEquals(headers.get(entry.getKey()).get(0), entry.getValue());
}
String payload = "12345678910";
byte[] outputBytes = payload.getBytes(StandardCharsets.UTF_8);
Expand All @@ -156,7 +151,7 @@ public void testRequestHeaders() throws IOException, URISyntaxException
inputStream = HttpEntity.openInputStream(url, "", null, 0, requestHeaders);
inputStreamPartial = HttpEntity.openInputStream(url, "", null, 5, requestHeaders);
inputStream.skip(5);
Assert.assertTrue(IOUtils.contentEquals(inputStream, inputStreamPartial));
Assertions.assertTrue(IOUtils.contentEquals(inputStream, inputStreamPartial));
}
finally {
IOUtils.closeQuietly(inputStream);
Expand Down
Loading
Loading