Skip to content

Commit

Permalink
Some new tests and todos
Browse files Browse the repository at this point in the history
  • Loading branch information
LesTR committed Jan 13, 2020
1 parent 11d4096 commit 7c2b19d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public <T> Optional<KeyValue<T>> get(
return Optional.empty();
} else {
return Optional.of(
KeyValue.<T>of(
KeyValue.of(
getEntityDescriptor(),
desc,
key,
Expand All @@ -74,6 +74,7 @@ public <T> Optional<KeyValue<T>> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,7 +33,7 @@ public JdbcDataAccessorTest() throws URISyntaxException {
}

@Test(expected = IllegalStateException.class)
public void testInitializeWithoutSqlFactory() {
public void initializeWithoutSqlFactoryTest() {
Map<String, Object> cfg =
Collections.singletonMap(
JdbcDataAccessor.JDBC_RESULT_CONVERTER, TestConverter.class.getName());
Expand All @@ -43,7 +44,7 @@ public void testInitializeWithoutSqlFactory() {
}

@Test(expected = IllegalStateException.class)
public void testInitializeWithoutConverter() {
public void initializeWithoutConverterTest() {
Map<String, Object> cfg =
Collections.singletonMap(
JdbcDataAccessor.JDBC_SQL_QUERY_FACTORY, HsqldbSqlStatementFactory.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@
*/
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;
import java.util.List;
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 {
Expand Down Expand Up @@ -96,4 +99,15 @@ public void getNotExistsTest() {
Optional<KeyValue<Byte[]>> keyValue = accessor.newRandomAccessReader().get("12345", attr);
assertFalse(keyValue.isPresent());
}

@Test
public void getInvalidAttributeTest() throws URISyntaxException {
AttributeDescriptor<byte[]> missing = AttributeDescriptor
.newBuilder(repository)
.setEntity(entity.getName())
.setName("missing")
.setSchemeUri(new URI("bytes:///"))
.build();
assertFalse(accessor.newRandomAccessReader().get("key", missing).isPresent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +64,27 @@ public void writeFailTest() {
writeElement(accessor, element);
}

@Test
public void writeIllegalAttribute() throws URISyntaxException {
AttributeDescriptor<byte[]> 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()) {
Expand Down

0 comments on commit 7c2b19d

Please sign in to comment.