Skip to content
Open
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 @@ -243,7 +243,7 @@ public Content.Chunk read() {
return last;
}
lockedSetTerminal(Content.Chunk.EOF);
} catch (Exception e) {
} catch (IOException e) {
lockedSetTerminal(Content.Chunk.from(e, true));
}
}
Expand Down Expand Up @@ -295,11 +295,10 @@ public boolean rewind() {
offsetRemaining = 0;
totalRead = 0;
return true;
} catch (Exception e) {
} catch (IOException e) {
Comment thread
efegokdemir marked this conversation as resolved.
lockedSetTerminal(Content.Chunk.from(e, true));
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,39 @@
*/
package org.eclipse.aether.transport.jetty;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SeekableByteChannel;

import org.eclipse.jetty.io.ByteBufferPool;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;

class PutTaskRequestContentTest {
@Test
void readPropagatesUnexpectedRuntimeExceptionsFromChannel() {
ReadableByteChannel channel = new ReadableByteChannel() {
@Override
public int read(ByteBuffer destination) {
throw new IllegalStateException("unexpected read failure");
}

@Override
public boolean isOpen() {
return true;
}

@Override
public void close() {}
};
PutTaskRequestContent content = new PutTaskRequestContent(ByteBufferPool.SIZED_NON_POOLING, () -> channel);

assertThrows(IllegalStateException.class, content::read);
}

@Test
void readPropagatesErrorsFromChannel() {
ReadableByteChannel channel = new ReadableByteChannel() {
Expand All @@ -49,6 +72,52 @@ public void close() {}
assertThrows(AssertionError.class, content::read);
}

@Test
void rewindPropagatesUnexpectedRuntimeExceptionsFromSeekableChannel() {
SeekableByteChannel channel = new SeekableByteChannel() {
@Override
public int read(ByteBuffer destination) {
return -1;
}

@Override
public int write(ByteBuffer source) {
return 0;
}

@Override
public long position() {
return 0;
}

@Override
public SeekableByteChannel position(long newPosition) {
throw new IllegalStateException("unexpected rewind failure");
}

@Override
public long size() {
return 0;
}

@Override
public SeekableByteChannel truncate(long size) {
return this;
}

@Override
public boolean isOpen() {
return true;
}

@Override
public void close() {}
};
PutTaskRequestContent content = new PutTaskRequestContent(ByteBufferPool.SIZED_NON_POOLING, () -> channel);

assertThrows(IllegalStateException.class, content::rewind);
}

@Test
void rewindPropagatesErrorsFromSeekableChannel() {
SeekableByteChannel channel = new SeekableByteChannel() {
Expand Down Expand Up @@ -94,4 +163,50 @@ public void close() {}

assertThrows(AssertionError.class, content::rewind);
}

@Test
void rewindReturnsFalseWhenPositionFailsWithIOException() {
SeekableByteChannel channel = new SeekableByteChannel() {
@Override
public int read(ByteBuffer destination) {
return -1;
}

@Override
public int write(ByteBuffer source) {
return 0;
}

@Override
public long position() {
return 0;
}

@Override
public SeekableByteChannel position(long newPosition) throws IOException {
throw new IOException("rewind failed");
}

@Override
public long size() {
return 0;
}

@Override
public SeekableByteChannel truncate(long size) {
return this;
}

@Override
public boolean isOpen() {
return true;
}

@Override
public void close() {}
};
PutTaskRequestContent content = new PutTaskRequestContent(ByteBufferPool.SIZED_NON_POOLING, () -> channel);

assertFalse(content.rewind());
}
}
Loading