[BUGFIX] Fix off-by-one in truncation logic

Now, the truncation is only triggered if more than MAX_ENTRIES could
have been returned.
This commit is contained in:
Julian Knutsen 2019-11-21 11:37:55 -08:00
parent e7673407f1
commit 00128d912d
No known key found for this signature in database
GPG Key ID: D85F536DB3615B2D
2 changed files with 3 additions and 5 deletions

View File

@ -248,7 +248,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
objToPayload.apply(networkPayload))) objToPayload.apply(networkPayload)))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
if (limit.get() <= 0) if (limit.get() < 0)
outTruncated.set(true); outTruncated.set(true);
return filteredResults; return filteredResults;

View File

@ -189,7 +189,6 @@ public class P2PDataStorageBuildGetDataResponseTest {
} }
// TESTCASE: Given a GetDataRequest w/o known PNP, send it back // TESTCASE: Given a GetDataRequest w/o known PNP, send it back
// XXXBUGXXX: Truncation return has off-by-one error
@Test @Test
public void buildGetDataResponse_unknownPNPSendBack() { public void buildGetDataResponse_unknownPNPSendBack() {
PersistableNetworkPayload onlyLocal = new PersistableNetworkPayloadStub(new byte[]{1}); PersistableNetworkPayload onlyLocal = new PersistableNetworkPayloadStub(new byte[]{1});
@ -204,7 +203,7 @@ public class P2PDataStorageBuildGetDataResponseTest {
AtomicBoolean outPSETruncated = new AtomicBoolean(false); AtomicBoolean outPSETruncated = new AtomicBoolean(false);
Capabilities peerCapabilities = new Capabilities(); Capabilities peerCapabilities = new Capabilities();
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); Assert.assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); Assert.assertFalse(outPSETruncated.get());
@ -355,7 +354,6 @@ public class P2PDataStorageBuildGetDataResponseTest {
} }
// TESTCASE: Given a GetDataRequest w/o known PSE, send it back // TESTCASE: Given a GetDataRequest w/o known PSE, send it back
// XXXBUGXXX: Truncation return has off-by-one error
@Test @Test
public void buildGetDataResponse_unknownPSESendBack() throws NoSuchAlgorithmException { public void buildGetDataResponse_unknownPSESendBack() throws NoSuchAlgorithmException {
ProtectedStorageEntry onlyLocal = getProtectedStorageEntryForAdd(); ProtectedStorageEntry onlyLocal = getProtectedStorageEntryForAdd();
@ -369,7 +367,7 @@ public class P2PDataStorageBuildGetDataResponseTest {
AtomicBoolean outPSETruncated = new AtomicBoolean(false); AtomicBoolean outPSETruncated = new AtomicBoolean(false);
Capabilities peerCapabilities = new Capabilities(); Capabilities peerCapabilities = new Capabilities();
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); Assert.assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); Assert.assertFalse(outPSETruncated.get());