Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>uk.ac.standrews.cs</groupId>
<artifactId>common-pom</artifactId>
<version>4.0-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
</parent>

<artifactId>population-records</artifactId>
Expand All @@ -49,9 +49,9 @@
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version> <!-- Use the latest version -->
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>5.26.9</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public void addMarriage(Marriage marriage) throws BucketException {

public static final int RECORDS_IMPORTED_PER_TRANSACTION = 10000;

private <T extends LXP> void importRecords(IBucket<T> bucket, Iterable<LXP> records) throws BucketException {
@SuppressWarnings("unchecked")
private <T extends LXP> void importRecords(IBucket<T> bucket, Iterable<LXP> records) throws BucketException {

final ITransactionManager transaction_manager = Store.getInstance().getTransactionManager();
final boolean auto_commit_previously_enabled = transaction_manager.isAutoCommitEnabled();
Expand Down Expand Up @@ -131,7 +132,7 @@ private <T extends LXP> Iterable<T> getRecords(IBucket<T> bucket) {

return () -> new Iterator<>() {

final List<String> object_ids = bucket.getObjectIds();
final List<Long> object_ids = bucket.getObjectIds();
final int bucket_size = object_ids.size();
int next_index = 0;

Expand Down Expand Up @@ -251,7 +252,7 @@ public static String[] getBucketNames() {
return new String[]{BIRTHS_BUCKET_NAME, DEATHS_BUCKET_NAME, MARRIAGES_BUCKET_NAME};
}

public IBucket getBucket(String bucketName) {
public IBucket<?> getBucket(String bucketName) {
switch (bucketName) {
case BIRTHS_BUCKET_NAME:
return births;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Birth() {
super();
}

public Birth(String persistent_object_id, Map properties, IBucket bucket) throws PersistentObjectException {
public Birth(long persistent_object_id, Map properties, IBucket bucket) throws PersistentObjectException {

super(persistent_object_id, properties, bucket);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Death() {
super();
}

public Death(String persistent_Object_id, Map properties, IBucket bucket) throws PersistentObjectException {
public Death(long persistent_Object_id, Map properties, IBucket bucket) throws PersistentObjectException {

super(persistent_Object_id, properties, bucket);
}
Expand All @@ -75,7 +75,7 @@ public boolean equals(final Object o) {

@Override
public int hashCode() {
return Long.valueOf(this.getId()).hashCode();
return Long.valueOf(getId()).hashCode();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Marriage() {
super();
}

public Marriage(String persistent_object_id, Map properties, IBucket bucket) throws PersistentObjectException {
public Marriage(long persistent_object_id, Map properties, IBucket bucket) throws PersistentObjectException {

super(persistent_object_id, properties, bucket);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright 2021 Systems Research Group, University of St Andrews:
* <https://github.com/stacs-srg>
*
* This file is part of the module population-records.
*
* population-records is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* population-records is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with population-records. If not, see
* <http://www.gnu.org/licenses/>.
*/
package uk.ac.standrews.cs.population_records;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Session;
import org.neo4j.harness.Neo4j;
import org.neo4j.harness.Neo4jBuilders;

import uk.ac.standrews.cs.neoStorr.impl.Store;
import uk.ac.standrews.cs.neoStorr.impl.exceptions.BucketException;
import uk.ac.standrews.cs.neoStorr.impl.exceptions.RepositoryException;
import uk.ac.standrews.cs.neoStorr.interfaces.IBucket;
import uk.ac.standrews.cs.population_records.record_types.*;

public class RecordRepositoryNeoTest {
static final RecordTypeTest BIRTH_TEST = new BirthTest();
static final RecordTypeTest MARRIAGE_TEST = new MarriageTest();
static final RecordTypeTest DEATH_TEST = new DeathTest();
static final String REPO_NAME_BASE = "test_";

static Neo4j neo4jDb;
String repoName;
RecordRepository repo;

@BeforeAll
static void setUpNeo() {
neo4jDb = Neo4jBuilders.newInProcessBuilder()
.build();
// Sets override for neo-storr.neoDbCypherBridge
System.setProperty("NeoDBTestURL", neo4jDb.boltURI().toString());
}

@BeforeEach
void setUpRepo() {
repoName = REPO_NAME_BASE + System.nanoTime();
repo = new RecordRepository(repoName);
}

@AfterEach
void tearDown() throws RepositoryException {
Store.getInstance().deleteRepository(repoName);
assertFalse(Store.getInstance().repositoryExists(repoName));
repo = null;
}

@AfterAll
static void tearDownNeo() {
Store.getInstance().close();
System.clearProperty("NeoDBTestURL");

if (neo4jDb!= null) neo4jDb.close();
neo4jDb = null;
}

@Test
public void testNeo4jConnection() {
String testString = "Hello world";
Driver driver = GraphDatabase.driver(neo4jDb.boltURI(), AuthTokens.none());

try (Session session = driver.session()) {
String response = session.run("RETURN '"+testString+"'").single().get(0).asString();
assertEquals(testString, response);
}
}


@Test
void testAddAndGetBirthRecord() throws BucketException, RepositoryException, IOException {
Birth birth = new Birth(BIRTH_TEST.datasetNoRecords, BIRTH_TEST.testRecords.get(0));
repo.addBirth(birth);

assertEquals(1, repo.getNumberOfBirths());

Birth retrieved = repo.getBirths().iterator().next();
assertEquals(birth, retrieved);
}

@Test
void testAddAndGetMarriageRecord() throws BucketException, RepositoryException, IOException {
Marriage marriage = new Marriage(MARRIAGE_TEST.datasetNoRecords, MARRIAGE_TEST.testRecords.get(0));
repo.addMarriage(marriage);

assertEquals(1, repo.getNumberOfMarriages());

Marriage retrieved = repo.getMarriages().iterator().next();
assertEquals(marriage, retrieved);
}

@Test
void testAddAndGetDeathRecord() throws BucketException, RepositoryException, IOException {
Death death = new Death(DEATH_TEST.datasetNoRecords, DEATH_TEST.testRecords.get(0));
repo.addDeath(death);

assertEquals(1, repo.getNumberOfDeaths());

Death retrieved = repo.getDeaths().iterator().next();
assertEquals(death, retrieved);
}

@Test
void testDeleteBuckets() throws RepositoryException {
repo.deleteBirthsBucket();
repo.deleteDeathsBucket();
repo.deleteMarriagesBucket();

for (String x : RecordRepository.getBucketNames()) {
assertThrows(RepositoryException.class, () -> {
Store.getInstance().getRepository(repoName).getBucket(x);
});
}
}

@Test
void testGetBuckets() {
for (String x : RecordRepository.getBucketNames()) {
assertNotNull(repo.getBucket(x));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2021 Systems Research Group, University of St Andrews:
* <https://github.com/stacs-srg>
*
* This file is part of the module population-records.
*
* population-records is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* population-records is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with population-records. If not, see
* <http://www.gnu.org/licenses/>.
*/
package uk.ac.standrews.cs.population_records;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;

public class RecordRepositoryTest {
@Test
void testGetBucketNames() {
List<String> bucketNames = Arrays.asList(RecordRepository.getBucketNames());
assertTrue(bucketNames.contains("birth_records"));
assertTrue(bucketNames.contains("marriage_records"));
assertTrue(bucketNames.contains("death_records"));
}
}
Loading
Loading