Skip to content

Commit

Permalink
Add state reset on close of AbstractPaginatedDataItemReader
Browse files Browse the repository at this point in the history
Resolves #1086
  • Loading branch information
hpoettker authored and fmbenhassine committed Dec 17, 2024
1 parent 7678949 commit 2bd3c15
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2023 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -103,6 +103,14 @@ protected void doOpen() throws Exception {

@Override
protected void doClose() throws Exception {
this.lock.lock();
try {
this.page = 0;
this.results = null;
}
finally {
this.lock.unlock();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2023 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -34,6 +35,7 @@
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -347,4 +349,18 @@ void testSortThrowsExceptionWhenInvokedWithNull() {
.withMessage("Sorts must not be null");
}

@Test
void testClose() throws Exception {
// given
when(template.find(any(), any())).thenReturn(List.of("string"));
reader.read();

// when
reader.close();

// then
assertEquals(0, reader.page);
assertNull(reader.results);
}

}

0 comments on commit 2bd3c15

Please sign in to comment.