-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Reverse ordering support for Task API #816
base: main
Are you sure you want to change the base?
Changes from all commits
56c2433
7e0e2d1
bb0c3f3
86b6d60
9d87521
6b83259
0b72a1c
4e94a85
64cd59c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,16 @@ | |
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.hamcrest.Matchers.nullValue; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.meilisearch.integration.classes.AbstractIT; | ||
import com.meilisearch.integration.classes.TestData; | ||
import com.meilisearch.sdk.Index; | ||
import com.meilisearch.sdk.model.*; | ||
import com.meilisearch.sdk.utils.Movie; | ||
import java.util.Date; | ||
import java.time.Instant; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Tag; | ||
|
@@ -32,6 +34,7 @@ public void initialize() { | |
this.setUp(); | ||
this.setUpJacksonClient(); | ||
if (testData == null) testData = this.getTestData(MOVIES_INDEX, Movie.class); | ||
TimeZone.setDefault(TimeZone.getTimeZone("UTC")); | ||
} | ||
|
||
@AfterAll | ||
|
@@ -202,6 +205,38 @@ public void testClientGetTasksAllQueryParameters() throws Exception { | |
assertThat(result.getNext(), is(notNullValue())); | ||
assertThat(result.getResults().length, is(notNullValue())); | ||
} | ||
/** Test to check if task list is reversed when enabled */ | ||
@Test | ||
public void testGetTasksInReverse() { | ||
String indexUid = "tasksOnReverseOrder"; | ||
Date currentTime = Date.from(Instant.now()); | ||
TestData<Movie> testData = this.getTestData(MOVIES_INDEX, Movie.class); | ||
|
||
TaskInfo taskA = client.index(indexUid).addDocuments(testData.getRaw()); | ||
TaskInfo taskB = client.index(indexUid).addDocuments(testData.getRaw()); | ||
|
||
client.waitForTask(taskA.getTaskUid()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you wait for the last task the first one will be finished in any case so you can remove this line. |
||
client.waitForTask(taskB.getTaskUid()); | ||
|
||
Task[] defaultTaskList = | ||
client.getTasks(new TasksQuery().setAfterEnqueuedAt(currentTime)).getResults(); | ||
Task[] reversedTaskList = | ||
client.getTasks(new TasksQuery().setAfterEnqueuedAt(currentTime).setReverse(true)) | ||
.getResults(); | ||
Comment on lines
+221
to
+225
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you map only the task ids here, and then you assert them later, so the test will be less complex to read. |
||
|
||
List<Integer> originalTaskOrder = | ||
Arrays.stream(defaultTaskList).map(Task::getUid).collect(Collectors.toList()); | ||
List<Integer> reversedTaskOrder = | ||
Arrays.stream(reversedTaskList).map(Task::getUid).collect(Collectors.toList()); | ||
assertFalse(originalTaskOrder.isEmpty()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also remove one of these assertions. |
||
assertFalse(reversedTaskOrder.isEmpty()); | ||
assertIterableEquals( | ||
originalTaskOrder, | ||
reversedTaskOrder.stream() | ||
.sorted(Collections.reverseOrder()) | ||
.collect(Collectors.toList()), | ||
"The lists are not reversed versions of each other"); | ||
} | ||
|
||
/** Test Cancel Task */ | ||
@Test | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,20 @@ | |
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Date; | ||
import java.util.TimeZone; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class URLBuilderTest { | ||
|
||
private final URLBuilder classToTest = new URLBuilder(); | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
TimeZone.setDefault(TimeZone.getTimeZone("UTC")); | ||
} | ||
|
||
Comment on lines
+18
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you need to set this? And if "yes" why not to set this for the whole test suite? |
||
@Test | ||
void addSubroute() { | ||
classToTest.addSubroute("route"); | ||
|
@@ -92,28 +98,20 @@ void addParameterStringIntArray() { | |
|
||
@Test | ||
void addParameterStringDate() throws Exception { | ||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | ||
Date date = format.parse("2042-01-30"); | ||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); | ||
Date date = format.parse("2042-01-30T10:30:00-05:00"); | ||
|
||
classToTest.addParameter("parameter1", date); | ||
String parameterDate1 = | ||
classToTest | ||
.getParams() | ||
.toString() | ||
.substring(12, classToTest.getParams().toString().length()); | ||
assertDoesNotThrow(() -> DateTimeFormatter.ISO_DATE.parse(parameterDate1)); | ||
assertThat(classToTest.getParams().toString(), is(equalTo("?parameter1=2042-01-30"))); | ||
String parameterDate1 = classToTest.getParams().substring(12); | ||
assertDoesNotThrow(() -> format.parse(parameterDate1)); | ||
assertEquals(classToTest.getParams().toString(), "?parameter1=2042-01-30T15:30:00Z"); | ||
|
||
classToTest.addParameter("parameter2", date); | ||
String parameterDate2 = | ||
classToTest | ||
.getParams() | ||
.toString() | ||
.substring(34, classToTest.getParams().toString().length()); | ||
assertDoesNotThrow(() -> DateTimeFormatter.ISO_DATE.parse(parameterDate2)); | ||
assertThat( | ||
String parameterDate2 = classToTest.getParams().substring(44); | ||
assertDoesNotThrow(() -> format.parse(parameterDate2)); | ||
assertEquals( | ||
classToTest.getParams().toString(), | ||
is(equalTo("?parameter1=2042-01-30¶meter2=2042-01-30"))); | ||
"?parameter1=2042-01-30T15:30:00Z¶meter2=2042-01-30T15:30:00Z"); | ||
} | ||
|
||
@Test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to explain what you're testing, this is usually a smell that your test is too complex. Which is not the case :)