-
Notifications
You must be signed in to change notification settings - Fork 122
Add integration tests, Docker on CI, and implement waitForPendingUpdate #32
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2278605
Add basic Indexes and Documents tests, run integration tests in CI wi…
eskombro 6e051f1
Add waitForPendingUpdateMethod
eskombro 24b2766
Update src/main/java/com/meilisearch/sdk/Index.java
eskombro 39f8f2f
Update src/main/java/com/meilisearch/sdk/Index.java
eskombro 3d4bc47
Review: test refactor
eskombro 0c38c80
Replace moviesStringToJson
eskombro 1d0fedf
move json file to /src/test/ressources
eskombro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,77 @@ | ||
package com.meilisearch.sdk; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
|
||
import com.google.gson.Gson; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
public class DocumentsTest { | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
Index meilisearchIndex; | ||
public class DocumentsTest { | ||
|
||
Client ms; | ||
Gson gson = new Gson(); | ||
TestUtils testUtils = new TestUtils(); | ||
|
||
@BeforeEach | ||
public void initialize() { | ||
Client ms = new Client(new Config("http://localhost:7700", "")); | ||
|
||
try { | ||
// TODO: add uid of index for test | ||
this.meilisearchIndex = ms.getIndex("movies"); | ||
} catch (Exception e) { | ||
|
||
} | ||
public void initialize() throws Exception { | ||
ms = new Client(new Config("http://localhost:7700", "masterKey")); | ||
} | ||
|
||
@Test | ||
public void get() throws Exception { | ||
// TODO: input identifier for test | ||
System.out.println(this.meilisearchIndex.getDocument("9999")); | ||
@AfterAll | ||
static void cleanMeiliSearch() throws Exception { | ||
new TestUtils().deleteAllIndexes(); | ||
} | ||
|
||
/** | ||
* Test Add single document | ||
*/ | ||
@Test | ||
public void getAll() throws Exception { | ||
System.out.println(this.meilisearchIndex.getDocuments()); | ||
} | ||
public void testAddDocumentsSingle() throws Exception { | ||
|
||
@Test | ||
public void add() throws Exception { | ||
String testDoc = "[{\n" + | ||
" \"id\": 9999,\n" + | ||
" \"title\": \"Shazam\",\n" + | ||
" \"poster\": \"https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg\",\n" + | ||
" \"overview\": \"A boy is given the ability to become an adult superhero in times of need with a single magic word.\",\n" + | ||
" \"release_date\": \"2019-03-23\"\n" + | ||
" }]"; | ||
// TODO: setup test document for 'add' | ||
System.out.println(this.meilisearchIndex.addDocuments("")); | ||
String indexUid = "addSingleDocument"; | ||
ms.createIndex(indexUid); | ||
Index index = ms.getIndex(indexUid); | ||
|
||
UpdateStatus updateInfo = this.gson.fromJson( | ||
index.addDocuments(this.testUtils.movies_data), | ||
UpdateStatus.class | ||
); | ||
|
||
index.waitForPendingUpdate(updateInfo.getUpdateId()); | ||
Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); | ||
for (int i=0; i<movies.length; i++) { | ||
assertEquals(movies[i].title, this.testUtils.movies[i].title); | ||
} | ||
} | ||
|
||
/** | ||
* Test Add multiple documents | ||
*/ | ||
@Test | ||
public void delete() throws Exception { | ||
// TODO: input identifier for test | ||
System.out.println(this.meilisearchIndex.deleteDocument("")); | ||
} | ||
public void testAddDocumentsMultiple() throws Exception { | ||
|
||
@Test | ||
public void search() throws Exception { | ||
System.out.println(this.meilisearchIndex.search("Batman")); | ||
} | ||
String indexUid = "addMultipleDocuments"; | ||
ms.createIndex(indexUid); | ||
Index index = ms.getIndex(indexUid); | ||
|
||
@Test | ||
public void updates() throws Exception { | ||
System.out.println(this.meilisearchIndex.getUpdates()[0].toString()); | ||
UpdateStatus updateInfo = this.gson.fromJson( | ||
index.addDocuments(this.testUtils.movies_data), | ||
UpdateStatus.class | ||
); | ||
|
||
index.waitForPendingUpdate(updateInfo.getUpdateId()); | ||
Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); | ||
for (int i=0; i<movies.length; i++) { | ||
assertEquals(movies[i].title, this.testUtils.movies[i].title); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,142 @@ | ||
/* | ||
* This Java source file was generated by the Gradle 'init' task. | ||
*/ | ||
package com.meilisearch.sdk; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.Arrays; | ||
|
||
import com.google.gson.Gson; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
public class IndexesTest { | ||
|
||
Client ms; | ||
Gson gson = new Gson(); | ||
String primaryKey = "id"; | ||
TestUtils testUtils = new TestUtils(); | ||
|
||
@BeforeEach | ||
public void initialize() { | ||
ms = new Client(new Config("http://localhost:7700", "")); | ||
public void initializeClient() throws Exception { | ||
ms = new Client(new Config("http://localhost:7700", "masterKey")); | ||
} | ||
|
||
@Test | ||
public void createIndex() throws Exception { | ||
System.out.println(ms.createIndex("videos")); | ||
@AfterAll | ||
static void cleanMeiliSearch() throws Exception { | ||
new TestUtils().deleteAllIndexes(); | ||
} | ||
|
||
/** | ||
* Test Index creation without PrimaryKey | ||
*/ | ||
@Test | ||
public void getIndexes() throws Exception { | ||
Index[] meilisearchIndices = ms.getIndexList(); | ||
for (int a = 0; a < meilisearchIndices.length; a++) { | ||
System.out.println(meilisearchIndices[a]); | ||
} | ||
|
||
public void testCreateIndexWithoutPrimaryKey() throws Exception { | ||
String indexUid = "IndexesTest"; | ||
ms.createIndex(indexUid); | ||
Index index = ms.getIndex(indexUid); | ||
assertEquals(index.uid, indexUid); | ||
assertEquals(index.primaryKey, null); | ||
ms.deleteIndex(index.uid); | ||
} | ||
|
||
/** | ||
* Test Index creation with PrimaryKey | ||
*/ | ||
@Test | ||
public void getIndex() throws Exception { | ||
// TODO: input uid for test | ||
Index meilisearchIndex = ms.getIndex("movies"); | ||
System.out.println(meilisearchIndex); | ||
public void testCreateIndexWithPrimaryKey() throws Exception { | ||
String indexUid = "IndexesTest"; | ||
ms.createIndex(indexUid, this.primaryKey); | ||
Index index = ms.getIndex(indexUid); | ||
assertEquals(index.uid, indexUid); | ||
assertEquals(index.primaryKey, this.primaryKey); | ||
ms.deleteIndex(index.uid); | ||
} | ||
|
||
/** | ||
* Test update Index PrimaryKey | ||
*/ | ||
@Test | ||
public void put() throws Exception { | ||
|
||
public void testUpdateIndexPrimaryKey() throws Exception { | ||
String indexUid = "IndexesTest"; | ||
ms.createIndex(indexUid); | ||
Index index = ms.getIndex(indexUid); | ||
assertEquals(index.uid, indexUid); | ||
assertEquals(index.primaryKey, null); | ||
ms.updateIndex(indexUid, this.primaryKey); | ||
index = ms.getIndex(indexUid); | ||
assertEquals(index.uid, indexUid); | ||
assertEquals(index.primaryKey, this.primaryKey); | ||
ms.deleteIndex(index.uid); | ||
} | ||
|
||
/** | ||
* Test getIndexList | ||
*/ | ||
@Test | ||
public void testGetIndexList() throws Exception { | ||
String[] indexUids = {"IndexesTest", "IndexesTest2"}; | ||
ms.createIndex(indexUids[0]); | ||
ms.createIndex(indexUids[1], this.primaryKey); | ||
Index index1 = ms.getIndex(indexUids[0]); | ||
Index index2 = ms.getIndex(indexUids[1]); | ||
Index[] indexes = ms.getIndexList(); | ||
assertEquals(indexes.length, 2); | ||
assert(Arrays.stream(indexUids).anyMatch(indexUids[0]::equals)); | ||
assert(Arrays.stream(indexUids).anyMatch(indexUids[1]::equals)); | ||
ms.deleteIndex(indexUids[0]); | ||
ms.deleteIndex(indexUids[1]); | ||
} | ||
|
||
/** | ||
* Test waitForPendingUpdate | ||
*/ | ||
@Test | ||
public void update() throws Exception { | ||
System.out.println(ms.updateIndex("video", "videos_key")); | ||
public void testWaitForPendingUpdate() throws Exception { | ||
String indexUid = "IndexesTest2"; | ||
ms.createIndex(indexUid); | ||
Index index = ms.getIndex(indexUid); | ||
|
||
UpdateStatus updateInfo = this.gson.fromJson( | ||
index.addDocuments(this.testUtils.movies_data), | ||
UpdateStatus.class | ||
); | ||
|
||
index.waitForPendingUpdate(updateInfo.getUpdateId()); | ||
|
||
UpdateStatus updateStatus = this.gson.fromJson( | ||
index.getUpdate(updateInfo.getUpdateId()), | ||
UpdateStatus.class | ||
); | ||
|
||
assertEquals("processed", updateStatus.getStatus()); | ||
|
||
ms.deleteIndex(index.uid); | ||
} | ||
|
||
/** | ||
* Test waitForPendingUpdate timeoutInMs | ||
*/ | ||
@Test | ||
public void delete() throws Exception { | ||
System.out.println(ms.deleteIndex("videos")); | ||
public void testWaitForPendingUpdateTimoutInMs() throws Exception { | ||
String indexUid = "IndexesTest2"; | ||
ms.createIndex(indexUid); | ||
Index index = ms.getIndex(indexUid); | ||
|
||
UpdateStatus updateInfo = this.gson.fromJson( | ||
index.addDocuments(this.testUtils.movies_data), | ||
UpdateStatus.class | ||
); | ||
|
||
assertThrows( | ||
Exception.class, | ||
() -> index.waitForPendingUpdate(updateInfo.getUpdateId(), 0, 50) | ||
); | ||
|
||
ms.deleteIndex(index.uid); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.meilisearch.sdk; | ||
|
||
public class Movie { | ||
String id; | ||
String title; | ||
String poster; | ||
String overview; | ||
String release_date; | ||
String language; | ||
String[] genres ; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
maybe something like a
CompletableFuture<UpdateStatus>
would be better for something like this.Supply the updateId -> thenApply(...) the while loop -> call .get(timeout)