Skip to content
This repository was archived by the owner on Feb 5, 2020. It is now read-only.

Commit ee90375

Browse files
committed
Fix to update to latest Trellis API
1 parent fed1834 commit ee90375

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

impl/src/main/java/edu/si/trellis/CassandraBinary.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package edu.si.trellis;
22

3+
import static java.util.concurrent.CompletableFuture.completedFuture;
4+
35
import edu.si.trellis.query.binary.Read;
46
import edu.si.trellis.query.binary.ReadRange;
57

68
import java.io.IOException;
79
import java.io.InputStream;
810
import java.io.UncheckedIOException;
11+
import java.util.concurrent.CompletableFuture;
12+
import java.util.concurrent.CompletionStage;
913

1014
import org.apache.commons.io.input.BoundedInputStream;
1115
import org.apache.commons.rdf.api.IRI;
@@ -40,22 +44,23 @@ public CassandraBinary(IRI id, Read read, ReadRange readRange, int chunkLength)
4044
}
4145

4246
@Override
43-
public InputStream getContent() {
44-
return read.execute(id);
47+
public CompletionStage<InputStream> getContent() {
48+
return completedFuture(read.execute(id));
4549
}
4650

4751
@Override
48-
public BoundedInputStream getContent(int from, int to) {
52+
public CompletionStage<InputStream> getContent(int from, int to) {
4953
int firstChunk = from / chunkLength;
5054
int lastChunk = to / chunkLength;
5155
int chunkStreamStart = from % chunkLength;
5256
int rangeSize = to - from + 1; // +1 because range is inclusive
53-
try (InputStream retrieve = readRange.execute(id, firstChunk, lastChunk)) {
54-
// skip to fulfill lower end of range
55-
retrieve.skip(chunkStreamStart); // we needn't check the result; see BinaryReadQuery#retrieve
56-
return new BoundedInputStream(retrieve, rangeSize); // apply limit for upper end of range
57+
InputStream retrieve = readRange.execute(id, firstChunk, lastChunk);
58+
// skip to fulfill lower end of range
59+
try {
60+
retrieve.skip(chunkStreamStart);
5761
} catch (IOException e) {
5862
throw new UncheckedIOException(e);
59-
}
63+
} // we needn't check the result; see BinaryReadQuery#retrieve
64+
return completedFuture(new BoundedInputStream(retrieve, rangeSize)); // apply limit for upper end of range
6065
}
6166
}

impl/src/test/java/edu/si/trellis/CassandraBinaryServiceIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ void setAndGetSmallContent() throws IOException {
4242
connection.binaryService.setContent(builder(id).build(), testInput).join();
4343
}
4444

45-
try (InputStream got = connection.binaryService.get(id).join().getContent()) {
45+
try (InputStream got = connection.binaryService.get(id).join().getContent().toCompletableFuture().join()) {
4646
String reply = IOUtils.toString(got, UTF_8);
4747
assertEquals(content, reply);
4848
}
4949

50-
try (InputStream got = connection.binaryService.get(id).join().getContent(5, 11)) {
50+
try (InputStream got = connection.binaryService.get(id).join().getContent(5, 11).toCompletableFuture().join()) {
5151
String reply = IOUtils.toString(got, UTF_8);
5252
assertEquals(content.subSequence(5, 12), reply);
5353
}
@@ -77,11 +77,11 @@ void setAndGetMultiChunkContent() throws IOException {
7777
assertTrue(got.isDone());
7878

7979
try (InputStream testData = new FileInputStream("src/test/resources/test.jpg");
80-
InputStream content = binary.getContent()) {
80+
InputStream content = binary.getContent().toCompletableFuture().join()) {
8181
assertTrue(contentEquals(testData, content), "Didn't retrieve correct content!");
8282
}
8383

84-
try (InputStream content = binary.getContent()) {
84+
try (InputStream content = binary.getContent().toCompletableFuture().join()) {
8585
String digest = DigestUtils.md5Hex(content);
8686
assertEquals(md5sum, digest);
8787
}
@@ -102,11 +102,11 @@ void varyChunkSizeFromDefault() throws IOException, InterruptedException, Execut
102102
assertTrue(got.isDone());
103103

104104
try (InputStream testData = new FileInputStream("src/test/resources/test.jpg");
105-
InputStream content = binary.getContent()) {
105+
InputStream content = binary.getContent().toCompletableFuture().join()) {
106106
assertTrue(contentEquals(testData, content), "Didn't retrieve correct content!");
107107
}
108108

109-
try (InputStream content = binary.getContent()) {
109+
try (InputStream content = binary.getContent().toCompletableFuture().join()) {
110110
String digest = DigestUtils.md5Hex(content);
111111
assertEquals(md5sum, digest);
112112
}

impl/src/test/java/edu/si/trellis/CassandraBinaryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void someContent() {
7575
when(mockRead.execute(any())).thenReturn(mockInputStream1);
7676
CassandraBinary testCassandraBinary = new CassandraBinary(testId, mockRead, mockReadRange, testChunkSize);
7777

78-
final InputStream result = testCassandraBinary.getContent();
78+
final InputStream result = testCassandraBinary.getContent().toCompletableFuture().join();
7979
assertSame(mockInputStream1, result, "Got wrong InputStream!");
8080
}
8181

@@ -86,7 +86,7 @@ void aBitOfContent() throws IOException {
8686
when(mockReadRange.execute(any(), anyInt(), anyInt())).thenReturn(testInputStream);
8787
CassandraBinary testCassandraBinary = new CassandraBinary(testId, mockRead, mockReadRange, testChunkSize);
8888

89-
final InputStream content = testCassandraBinary.getContent(0, 10);
89+
final InputStream content = testCassandraBinary.getContent(0, 10).toCompletableFuture().join();
9090
byte[] result = new byte[3];
9191

9292
content.read(result);

webapp/src/main/resources/META-INF/beans.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" version="1.1"
44
bean-discovery-mode="all">
55
<alternatives>
6-
<!-- <class>class org.trellisldp.api.NoopMementoService</class> -->
6+
<class>org.trellisldp.api.NoopAuditService</class>
7+
<class>org.trellisldp.api.NoopEventService</class>
8+
<class>org.trellisldp.api.NoopNamespaceService</class>
79
</alternatives>
810
</beans>

0 commit comments

Comments
 (0)