-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
734 additions
and
315 deletions.
There are no files selected for viewing
This file contains 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 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
106 changes: 106 additions & 0 deletions
106
src/integrationTest/java/com/nucleodb/library/ExportTest.java
This file contains 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,106 @@ | ||
package com.nucleodb.library; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.nucleodb.library.database.tables.table.DataEntry; | ||
import com.nucleodb.library.database.tables.table.DataEntryProjection; | ||
import com.nucleodb.library.database.tables.table.DataTable; | ||
import com.nucleodb.library.database.utils.Serializer; | ||
import com.nucleodb.library.database.utils.exceptions.IncorrectDataEntryClassException; | ||
import com.nucleodb.library.database.utils.exceptions.IncorrectDataEntryObjectException; | ||
import com.nucleodb.library.database.utils.exceptions.MissingDataEntryConstructorsException; | ||
import com.nucleodb.library.models.Author; | ||
import com.nucleodb.library.models.AuthorDE; | ||
import com.nucleodb.library.mqs.kafka.KafkaConfiguration; | ||
import com.nucleodb.library.mqs.local.LocalConfiguration; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.beans.IntrospectionException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class ExportTest { | ||
NucleoDB nucleoDB; | ||
DataTable<AuthorDE> table; | ||
|
||
@BeforeEach | ||
public void createLocalDB() throws IncorrectDataEntryClassException, MissingDataEntryConstructorsException, IntrospectionException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IncorrectDataEntryObjectException, InterruptedException { | ||
nucleoDB = new NucleoDB( | ||
NucleoDB.DBType.ALL, | ||
c -> { | ||
c.getConnectionConfig().setMqsConfiguration(new KafkaConfiguration()); | ||
|
||
c.getConnectionConfig().setLoadSaved(true); | ||
c.getConnectionConfig().setJsonExport(true); | ||
c.getConnectionConfig().setSaveChanges(true); | ||
c.getConnectionConfig().setConnectionFileName("./data/connection.dat"); | ||
c.getConnectionConfig().setExportInterval(50); | ||
c.getConnectionConfig().setSaveInterval(50); | ||
}, | ||
c -> { | ||
c.getDataTableConfig().setMqsConfiguration(new KafkaConfiguration()); | ||
c.getDataTableConfig().setLoadSave(true); | ||
c.getDataTableConfig().setSaveChanges(true); | ||
c.getDataTableConfig().setJsonExport(true); | ||
c.getDataTableConfig().setTableFileName("./data/datatable.dat"); | ||
c.getDataTableConfig().setExportInterval(50); | ||
c.getDataTableConfig().setSaveInterval(50); | ||
}, | ||
c -> { | ||
c.setMqsConfiguration(new KafkaConfiguration()); | ||
}, | ||
"com.nucleodb.library.models" | ||
); | ||
table = nucleoDB.getTable(Author.class); | ||
System.out.println("STARTED"); | ||
table.saveSync(new AuthorDE(new Author("George Orwell", "science-fiction"))); | ||
} | ||
|
||
public AuthorDE copy(AuthorDE authorDE) throws JsonProcessingException { | ||
return Serializer.getObjectMapper().getOm().readValue(Serializer.getObjectMapper().getOm().writeValueAsString(authorDE), AuthorDE.class); | ||
} | ||
@AfterEach | ||
public void deleteEntries() { | ||
System.out.println("DONE"); | ||
table.getEntries().stream().map(author -> { | ||
try { | ||
return copy(author); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}).collect(Collectors.toSet()).forEach(author-> { | ||
try { | ||
table.deleteSync(author); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
try { | ||
Thread.sleep(2000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Test | ||
public void checkSaving() throws IncorrectDataEntryObjectException, InterruptedException { | ||
AuthorDE edgarAllenPoe = new AuthorDE(new Author("Edgar Allen Poe", "fiction")); | ||
table.saveSync(edgarAllenPoe); | ||
assertEquals( | ||
1, | ||
table.get( | ||
"id", | ||
edgarAllenPoe.getKey(), | ||
null | ||
).size() | ||
); | ||
Thread.sleep(5000); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/integrationTest/java/com/nucleodb/library/models/Author.java
This file contains 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,42 @@ | ||
package com.nucleodb.library.models; | ||
|
||
import com.nucleodb.library.database.index.TrieIndex; | ||
import com.nucleodb.library.database.index.annotation.Index; | ||
import com.nucleodb.library.database.tables.annotation.Table; | ||
|
||
import java.io.Serializable; | ||
import java.util.UUID; | ||
|
||
@Table(tableName = "authorIT", dataEntryClass = AuthorDE.class) | ||
public class Author implements Serializable { | ||
private static final long serialVersionUID = 1; | ||
@Index(type = TrieIndex.class) | ||
String name; | ||
|
||
@Index | ||
String areaOfInterest; | ||
|
||
public Author() { | ||
} | ||
|
||
public Author(String name, String areaOfInterest) { | ||
this.name = name; | ||
this.areaOfInterest = areaOfInterest; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getAreaOfInterest() { | ||
return areaOfInterest; | ||
} | ||
|
||
public void setAreaOfInterest(String areaOfInterest) { | ||
this.areaOfInterest = areaOfInterest; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/integrationTest/java/com/nucleodb/library/models/AuthorDE.java
This file contains 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,22 @@ | ||
package com.nucleodb.library.models; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.nucleodb.library.database.modifications.Create; | ||
import com.nucleodb.library.database.tables.table.DataEntry; | ||
|
||
public class AuthorDE extends DataEntry<Author>{ | ||
public AuthorDE(Author obj) { | ||
super(obj); | ||
} | ||
|
||
public AuthorDE(Create create) throws ClassNotFoundException, JsonProcessingException { | ||
super(create); | ||
} | ||
|
||
public AuthorDE() { | ||
} | ||
|
||
public AuthorDE(String key) { | ||
super(key); | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.