Search in sources :

Example 66 with Record

use of nikita.model.noark5.v4.Record in project neo4j by neo4j.

the class BoltCausalClusteringIT method executeWriteAndReadThroughBolt.

private int executeWriteAndReadThroughBolt(CoreClusterMember core) throws TimeoutException, InterruptedException {
    try (Driver driver = GraphDatabase.driver(core.routingURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        return inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
            // when
            session.run("MERGE (n:Person {name: 'Jim'})").consume();
            Record record = session.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            return record.get("count").asInt();
        });
    }
}
Also used : Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record)

Example 67 with Record

use of nikita.model.noark5.v4.Record in project neo4j by neo4j.

the class BoltCausalClusteringIT method bookmarksShouldWorkWithDriverPinnedToSingleServer.

// Ensure that Bookmarks work with single instances using a driver created using a bolt[not+routing] URI.
@Test
public void bookmarksShouldWorkWithDriverPinnedToSingleServer() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    try (Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        String bookmark = inExpirableSession(driver, Driver::session, (session) -> {
            try (Transaction tx = session.beginTransaction()) {
                tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
                tx.success();
            }
            return session.lastBookmark();
        });
        assertNotNull(bookmark);
        try (Session session = driver.session();
            Transaction tx = session.beginTransaction(bookmark)) {
            Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            assertEquals(1, record.get("count").asInt());
            tx.success();
        }
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 68 with Record

use of nikita.model.noark5.v4.Record in project neo4j by neo4j.

the class BoltCausalClusteringIT method shouldUseBookmarkFromAReadSessionInAWriteSession.

@Test
public void shouldUseBookmarkFromAReadSessionInAWriteSession() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    try (Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
            session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
            return null;
        });
        String bookmark;
        try (Session session = driver.session(AccessMode.READ)) {
            try (Transaction tx = session.beginTransaction()) {
                tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
                tx.success();
            }
            bookmark = session.lastBookmark();
        }
        assertNotNull(bookmark);
        inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
            try (Transaction tx = session.beginTransaction(bookmark)) {
                tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
                tx.success();
            }
            return null;
        });
        try (Session session = driver.session()) {
            Record record = session.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            assertEquals(2, record.get("count").asInt());
        }
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 69 with Record

use of nikita.model.noark5.v4.Record in project neo4j by neo4j.

the class BoltCausalClusteringIT method executeReadQuery.

private void executeReadQuery(String bookmark, Session session) {
    try (Transaction tx = session.beginTransaction(bookmark)) {
        Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
        assertEquals(1, record.get("count").asInt());
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) Record(org.neo4j.driver.v1.Record)

Example 70 with Record

use of nikita.model.noark5.v4.Record in project ORCID-Source by ORCID.

the class RecordManagerTest method testGetRecord.

@Test
public void testGetRecord() {
    Record record = RecordManager.getRecord(ORCID);
    assertNotNull(record);
    assertNotNull(record.getActivitiesSummary());
    assertNotNull(record.getPerson());
    Person person = record.getPerson();
    assertNotNull(person.getExternalIdentifiers());
    assertNotNull(person.getExternalIdentifiers().getExternalIdentifiers());
    assertEquals(5, person.getExternalIdentifiers().getExternalIdentifiers().size());
    assertNotNull(person.getResearcherUrls());
    assertNotNull(person.getResearcherUrls().getResearcherUrls());
    assertEquals(5, person.getResearcherUrls().getResearcherUrls().size());
    assertNotNull(person.getOtherNames());
    assertNotNull(person.getOtherNames().getOtherNames());
    assertEquals(5, person.getOtherNames().getOtherNames().size());
    assertNotNull(person.getAddresses());
    assertNotNull(person.getAddresses().getAddress());
    assertEquals(5, person.getAddresses().getAddress().size());
    assertNotNull(person.getKeywords());
    assertNotNull(person.getKeywords().getKeywords());
    assertEquals(5, person.getKeywords().getKeywords().size());
    assertNotNull(person.getEmails());
    assertNotNull(person.getEmails().getEmails());
    assertEquals(5, person.getEmails().getEmails().size());
    assertNotNull(person.getBiography());
    assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility());
    assertEquals("Biography for 0000-0000-0000-0003", person.getBiography().getContent());
    assertNotNull(person.getName());
    assertNotNull(person.getName().getCreditName());
    assertEquals("Credit Name", person.getName().getCreditName().getContent());
    assertNotNull(person.getName().getFamilyName());
    assertEquals("Family Name", person.getName().getFamilyName().getContent());
    assertNotNull(person.getName().getGivenNames());
    assertEquals("Given Names", person.getName().getGivenNames().getContent());
    assertEquals(Visibility.PUBLIC, person.getName().getVisibility());
    ActivitiesSummary activities = record.getActivitiesSummary();
    assertNotNull(activities);
    assertNotNull(activities.getEducations());
    assertNotNull(activities.getEducations().getSummaries());
    assertEquals(5, activities.getEducations().getSummaries().size());
    assertNotNull(activities.getEmployments());
    assertNotNull(activities.getEmployments().getSummaries());
    assertEquals(5, activities.getEmployments().getSummaries().size());
    assertNotNull(activities.getFundings());
    assertNotNull(activities.getFundings().getFundingGroup());
    assertEquals(5, activities.getFundings().getFundingGroup().size());
    assertNotNull(activities.getPeerReviews());
    assertNotNull(activities.getPeerReviews().getPeerReviewGroup());
    assertEquals(5, activities.getPeerReviews().getPeerReviewGroup().size());
    assertNotNull(activities.getWorks());
    assertNotNull(activities.getWorks().getWorkGroup());
    assertEquals(5, activities.getWorks().getWorkGroup().size());
}
Also used : Record(org.orcid.jaxb.model.record_v2.Record) Person(org.orcid.jaxb.model.record_v2.Person) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Aggregations

Test (org.junit.Test)72 Record (org.orcid.jaxb.model.record_v2.Record)62 Counted (com.codahale.metrics.annotation.Counted)28 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponses (io.swagger.annotations.ApiResponses)27 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)25 Person (org.orcid.jaxb.model.record_v2.Person)22 Email (org.orcid.jaxb.model.record_v2.Email)20 Record (nikita.model.noark5.v4.Record)19 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)19 Address (org.orcid.jaxb.model.record_v2.Address)19 Name (org.orcid.jaxb.model.record_v2.Name)19 OtherName (org.orcid.jaxb.model.record_v2.OtherName)19 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)19 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)18 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)18 Keyword (org.orcid.jaxb.model.record_v2.Keyword)18 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)18 Record (org.neo4j.driver.v1.Record)17