Search in sources :

Example 1 with Record

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

the class BoltCausalClusteringIT method shouldUseBookmarkFromAWriteSessionInAReadSession.

@Test
public void shouldUseBookmarkFromAWriteSessionInAReadSession() throws Throwable {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    ReadReplica readReplica = cluster.getReadReplicaById(0);
    readReplica.txPollingClient().stop();
    Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"));
    String bookmark = inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
        try (Transaction tx = session.beginTransaction()) {
            tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
            tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
            tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Mark"));
            tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Chris"));
            tx.success();
        }
        return session.lastBookmark();
    });
    assertNotNull(bookmark);
    readReplica.txPollingClient().start();
    driver = GraphDatabase.driver(readReplica.directURI(), AuthTokens.basic("neo4j", "neo4j"));
    try (Session session = driver.session(AccessMode.READ)) {
        try (Transaction tx = session.beginTransaction(bookmark)) {
            Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            tx.success();
            assertEquals(4, record.get("count").asInt());
        }
    }
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) 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 2 with Record

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

the class BoltCausalClusteringIT method shouldHandleLeaderSwitch.

@Test
public void shouldHandleLeaderSwitch() throws Exception {
    // given
    cluster = clusterRule.startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    try (Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        // when
        try (Session session = driver.session()) {
            try (Transaction tx = session.beginTransaction()) {
                switchLeader(leader);
                tx.run("CREATE (person:Person {name: {name}, title: {title}})", parameters("name", "Webber", "title", "Mr"));
                tx.success();
            } catch (SessionExpiredException ignored) {
            // expected
            }
        }
        String bookmark = inExpirableSession(driver, Driver::session, s -> {
            try (Transaction tx = s.beginTransaction()) {
                tx.run("CREATE (person:Person {name: {name}, title: {title}})", parameters("name", "Webber", "title", "Mr"));
                tx.success();
            } catch (SessionExpiredException ignored) {
            }
            return s.lastBookmark();
        });
        // then
        try (Session session = driver.session(AccessMode.READ)) {
            try (Transaction tx = session.beginTransaction(bookmark)) {
                Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
                tx.success();
                assertEquals(1, record.get("count").asInt());
            }
        }
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) SessionExpiredException(org.neo4j.driver.v1.exceptions.SessionExpiredException) 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 3 with Record

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

the class BoltCausalClusteringIT method shouldReadAndWriteToANewSessionCreatedAfterALeaderSwitch.

/*
       Create a session with empty arg list (no AccessMode arg), in a driver that was initialized with a bolt+routing
       URI, and ensure that it
       a) works against the Leader for reads and writes before a leader switch, and
       b) receives a SESSION EXPIRED after a leader switch, and
       c) keeps working if a new session is created after that exception, again with no access mode specified.
     */
@Test
public void shouldReadAndWriteToANewSessionCreatedAfterALeaderSwitch() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    try (Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        inExpirableSession(driver, Driver::session, (session) -> {
            // execute a write/read query
            session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
            Record record = session.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            assertEquals(1, record.get("count").asInt());
            try {
                switchLeader(leader);
                session.run("CREATE (p:Person {name: {name} })").consume();
                fail("Should have thrown an exception as the leader went away mid session");
            } catch (SessionExpiredException sep) {
                // then
                assertEquals(String.format("Server at %s no longer accepts writes", leader.boltAdvertisedAddress()), sep.getMessage());
            } catch (InterruptedException e) {
            // ignored
            }
            return null;
        });
        inExpirableSession(driver, Driver::session, (session) -> {
            // execute a write/read query
            session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
            Record record = session.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            assertEquals(2, record.get("count").asInt());
            return null;
        });
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) SessionExpiredException(org.neo4j.driver.v1.exceptions.SessionExpiredException) Test(org.junit.Test)

Example 4 with Record

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

the class MemberV2ApiServiceVersionedDelegatorTest method test2_0.

@Test
public void test2_0() {
    SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0003", ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewRecord("0000-0000-0000-0003");
    Record record = (Record) response.getEntity();
    assertNotNull(record.getActivitiesSummary());
    ActivitiesSummary activitiesSummary = record.getActivitiesSummary();
    if (activitiesSummary.getEducations() != null) {
        activitiesSummary.getEducations().getSummaries().forEach(e -> assertSourceElement(e, false));
    }
    if (activitiesSummary.getEmployments() != null) {
        activitiesSummary.getEmployments().getSummaries().forEach(e -> assertSourceElement(e, false));
    }
    if (activitiesSummary.getFundings() != null) {
        activitiesSummary.getFundings().getFundingGroup().forEach(g -> {
            g.getFundingSummary().forEach(e -> assertSourceElement(e, false));
        });
    }
    if (activitiesSummary.getWorks() != null) {
        activitiesSummary.getWorks().getWorkGroup().forEach(g -> {
            g.getWorkSummary().forEach(e -> assertSourceElement(e, false));
        });
    }
    if (activitiesSummary.getPeerReviews() != null) {
        activitiesSummary.getPeerReviews().getPeerReviewGroup().forEach(g -> {
            g.getPeerReviewSummary().forEach(e -> assertSourceElement(e, false));
        });
    }
    assertNotNull(record.getPerson());
    Person person = record.getPerson();
    if (person.getAddresses() != null) {
        person.getAddresses().getAddress().forEach(e -> assertSourceElement(e, false));
    }
    if (person.getExternalIdentifiers() != null) {
        person.getExternalIdentifiers().getExternalIdentifiers().forEach(e -> assertSourceElement(e, false));
    }
    if (person.getKeywords() != null) {
        person.getKeywords().getKeywords().forEach(e -> assertSourceElement(e, false));
    }
    if (person.getOtherNames() != null) {
        person.getOtherNames().getOtherNames().forEach(e -> assertSourceElement(e, false));
    }
    if (person.getResearcherUrls() != null) {
        person.getResearcherUrls().getResearcherUrls().forEach(e -> assertSourceElement(e, false));
    }
}
Also used : Response(javax.ws.rs.core.Response) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) 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) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 5 with Record

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

the class MemberV2ApiServiceVersionedDelegatorTest method test2_1.

@Test
public void test2_1() {
    SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0003", ScopePathType.READ_LIMITED);
    Response response = serviceDelegator_v2_1.viewRecord("0000-0000-0000-0003");
    Record record = (Record) response.getEntity();
    assertNotNull(record.getActivitiesSummary());
    ActivitiesSummary activitiesSummary = record.getActivitiesSummary();
    if (activitiesSummary.getEducations() != null) {
        activitiesSummary.getEducations().getSummaries().forEach(e -> assertSourceElement(e, true));
    }
    if (activitiesSummary.getEmployments() != null) {
        activitiesSummary.getEmployments().getSummaries().forEach(e -> assertSourceElement(e, true));
    }
    if (activitiesSummary.getFundings() != null) {
        activitiesSummary.getFundings().getFundingGroup().forEach(g -> {
            g.getFundingSummary().forEach(e -> assertSourceElement(e, true));
        });
    }
    if (activitiesSummary.getWorks() != null) {
        activitiesSummary.getWorks().getWorkGroup().forEach(g -> {
            g.getWorkSummary().forEach(e -> assertSourceElement(e, true));
        });
    }
    if (activitiesSummary.getPeerReviews() != null) {
        activitiesSummary.getPeerReviews().getPeerReviewGroup().forEach(g -> {
            g.getPeerReviewSummary().forEach(e -> assertSourceElement(e, true));
        });
    }
    assertNotNull(record.getPerson());
    Person person = record.getPerson();
    if (person.getAddresses() != null) {
        person.getAddresses().getAddress().forEach(e -> assertSourceElement(e, true));
    }
    if (person.getExternalIdentifiers() != null) {
        person.getExternalIdentifiers().getExternalIdentifiers().forEach(e -> assertSourceElement(e, true));
    }
    if (person.getKeywords() != null) {
        person.getKeywords().getKeywords().forEach(e -> assertSourceElement(e, true));
    }
    if (person.getOtherNames() != null) {
        person.getOtherNames().getOtherNames().forEach(e -> assertSourceElement(e, true));
    }
    if (person.getResearcherUrls() != null) {
        person.getResearcherUrls().getResearcherUrls().forEach(e -> assertSourceElement(e, true));
    }
}
Also used : Response(javax.ws.rs.core.Response) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) 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) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

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