From 7c2b19d8524252322762cb12be096fb73becc447 Mon Sep 17 00:00:00 2001 From: Lukas Drbal Date: Tue, 14 Jan 2020 00:06:19 +0100 Subject: [PATCH] Some new tests and todos --- .../jdbc/JdbcOnlineAttributeReader.java | 3 ++- .../direct/jdbc/JdbcDataAccessorTest.java | 9 ++++---- .../jdbc/JdbcOnlineAttributeReaderTest.java | 22 ++++++++++++++---- .../jdbc/JdbcOnlineAttributeWriterTest.java | 23 +++++++++++++++++++ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeReader.java b/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeReader.java index e8171f57b..d12f351ec 100644 --- a/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeReader.java +++ b/direct/io-jdbc/src/main/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeReader.java @@ -64,7 +64,7 @@ public Optional> get( return Optional.empty(); } else { return Optional.of( - KeyValue.of( + KeyValue.of( getEntityDescriptor(), desc, key, @@ -74,6 +74,7 @@ public Optional> get( } } catch (SQLException e) { log.error("Error during query execution: {}", e.getMessage(), e); + //@TODO: Maybe re-throw exception in case of SQLSyntaxErrorException? return Optional.empty(); } } diff --git a/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcDataAccessorTest.java b/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcDataAccessorTest.java index d9ef9387e..4e3484c67 100644 --- a/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcDataAccessorTest.java +++ b/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcDataAccessorTest.java @@ -16,13 +16,14 @@ package cz.o2.proxima.direct.jdbc; import cz.o2.proxima.util.TestUtils; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Collections; import java.util.Map; -import lombok.extern.slf4j.Slf4j; -import org.junit.Test; @Slf4j public class JdbcDataAccessorTest extends JdbcBaseTest { @@ -32,7 +33,7 @@ public JdbcDataAccessorTest() throws URISyntaxException { } @Test(expected = IllegalStateException.class) - public void testInitializeWithoutSqlFactory() { + public void initializeWithoutSqlFactoryTest() { Map cfg = Collections.singletonMap( JdbcDataAccessor.JDBC_RESULT_CONVERTER, TestConverter.class.getName()); @@ -43,7 +44,7 @@ public void testInitializeWithoutSqlFactory() { } @Test(expected = IllegalStateException.class) - public void testInitializeWithoutConverter() { + public void initializeWithoutConverterTest() { Map cfg = Collections.singletonMap( JdbcDataAccessor.JDBC_SQL_QUERY_FACTORY, HsqldbSqlStatementFactory.class.getName()); diff --git a/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeReaderTest.java b/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeReaderTest.java index ee0ede4e7..58d766ac2 100644 --- a/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeReaderTest.java +++ b/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeReaderTest.java @@ -15,12 +15,15 @@ */ package cz.o2.proxima.direct.jdbc; -import static org.junit.Assert.*; - import cz.o2.proxima.direct.randomaccess.KeyValue; import cz.o2.proxima.direct.randomaccess.RandomAccessReader; +import cz.o2.proxima.repository.AttributeDescriptor; import cz.o2.proxima.storage.StreamElement; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + import java.io.IOException; +import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; @@ -28,8 +31,8 @@ import java.util.Objects; import java.util.Optional; import java.util.UUID; -import lombok.extern.slf4j.Slf4j; -import org.junit.Test; + +import static org.junit.Assert.*; @Slf4j public class JdbcOnlineAttributeReaderTest extends JdbcBaseTest { @@ -96,4 +99,15 @@ public void getNotExistsTest() { Optional> keyValue = accessor.newRandomAccessReader().get("12345", attr); assertFalse(keyValue.isPresent()); } + + @Test + public void getInvalidAttributeTest() throws URISyntaxException { + AttributeDescriptor missing = AttributeDescriptor + .newBuilder(repository) + .setEntity(entity.getName()) + .setName("missing") + .setSchemeUri(new URI("bytes:///")) + .build(); + assertFalse(accessor.newRandomAccessReader().get("key", missing).isPresent()); + } } diff --git a/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeWriterTest.java b/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeWriterTest.java index 4c34d12b4..bcdbce759 100644 --- a/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeWriterTest.java +++ b/direct/io-jdbc/src/test/java/cz/o2/proxima/direct/jdbc/JdbcOnlineAttributeWriterTest.java @@ -19,8 +19,10 @@ import cz.o2.proxima.direct.randomaccess.KeyValue; import cz.o2.proxima.direct.randomaccess.RandomAccessReader; +import cz.o2.proxima.repository.AttributeDescriptor; import cz.o2.proxima.storage.StreamElement; import java.io.IOException; +import java.net.URI; import java.net.URISyntaxException; import java.util.Optional; import java.util.UUID; @@ -62,6 +64,27 @@ public void writeFailTest() { writeElement(accessor, element); } + @Test + public void writeIllegalAttribute() throws URISyntaxException { + AttributeDescriptor missing = AttributeDescriptor + .newBuilder(repository) + .setEntity(entity.getName()) + .setName("missing") + .setSchemeUri(new URI("bytes:///")) + .build(); + + StreamElement element = + StreamElement.update( + entity, + missing, + UUID.randomUUID().toString(), + "key", + missing.getName(), + System.currentTimeMillis(), + "value".getBytes()); + assertFalse(writeElement(accessor, element).get()); + } + @Test public void deleteTest() throws IOException { try (RandomAccessReader reader = accessor.newRandomAccessReader()) {