Search in sources :

Example 21 with BounceProxyRecord

use of io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord in project joynr by bmwcarit.

the class DatabasesTest method testGetAssignableBounceProxies.

@Test
public void testGetAssignableBounceProxies() {
    List<BounceProxyRecord> assignableBounceProxies = bounceProxyDb.getAssignableBounceProxies();
    Assert.assertEquals(0, assignableBounceProxies.size());
    ControlledBounceProxyInformation bpInfo1 = new ControlledBounceProxyInformation("bp1.0", URI.create("http://www.joynr1.de/bp1/"));
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(1000l);
    bounceProxyDb.addBounceProxy(bpInfo1);
    assignableBounceProxies = bounceProxyDb.getAssignableBounceProxies();
    Assert.assertEquals(1, assignableBounceProxies.size());
    for (BounceProxyStatus status : BounceProxyStatus.values()) {
        BounceProxyRecord bpRecord = new BounceProxyRecord(bpInfo1);
        bpRecord.setStatus(status);
        Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(2000l);
        bounceProxyDb.updateBounceProxy(bpRecord);
        assignableBounceProxies = bounceProxyDb.getAssignableBounceProxies();
        if (status.isAssignable()) {
            Assert.assertEquals(1, assignableBounceProxies.size());
        } else {
            Assert.assertEquals(0, assignableBounceProxies.size());
        }
    }
}
Also used : BounceProxyStatus(io.joynr.messaging.info.BounceProxyStatus) BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Test(org.junit.Test)

Example 22 with BounceProxyRecord

use of io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord in project joynr by bmwcarit.

the class DatabasesTest method testAddBounceProxies.

@Test
public void testAddBounceProxies() {
    ControlledBounceProxyInformation bpInfo1 = new ControlledBounceProxyInformation("bp1.0", URI.create("http://www.joynr1.de/bp1/"));
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(1000l);
    bounceProxyDb.addBounceProxy(bpInfo1);
    List<BounceProxyRecord> assignableBounceProxies = bounceProxyDb.getAssignableBounceProxies();
    Assert.assertEquals(1, assignableBounceProxies.size());
    Assert.assertTrue(bounceProxyDb.containsBounceProxy("bp1.0"));
    Assert.assertFalse(bounceProxyDb.containsBounceProxy("bp2.0"));
    BounceProxyRecord bpRecord1 = bounceProxyDb.getBounceProxy("bp1.0");
    Assert.assertEquals("bp1.0", bpRecord1.getBounceProxyId());
    Assert.assertEquals("http://www.joynr1.de/bp1/", bpRecord1.getInfo().getLocation().toString());
    Assert.assertEquals(0, bpRecord1.getNumberOfAssignedChannels());
    Assert.assertEquals(BounceProxyRecord.ASSIGNMENT_TIMESTAMP_NEVER, bpRecord1.getLastAssignedTimestamp());
    Assert.assertEquals(1000l, bpRecord1.getFreshness().getTime());
    Assert.assertEquals(BounceProxyStatus.ALIVE, bpRecord1.getStatus());
    ControlledBounceProxyInformation bpInfo2 = new ControlledBounceProxyInformation("bp2.0", URI.create("http://www.joynr2.de/bp2/"));
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(2000l);
    bounceProxyDb.addBounceProxy(bpInfo2);
    assignableBounceProxies = bounceProxyDb.getAssignableBounceProxies();
    Assert.assertEquals(2, assignableBounceProxies.size());
    Assert.assertTrue(bounceProxyDb.containsBounceProxy("bp1.0"));
    Assert.assertTrue(bounceProxyDb.containsBounceProxy("bp2.0"));
    BounceProxyRecord bpRecord2 = bounceProxyDb.getBounceProxy("bp2.0");
    Assert.assertEquals("bp2.0", bpRecord2.getBounceProxyId());
    Assert.assertEquals("http://www.joynr2.de/bp2/", bpRecord2.getInfo().getLocation().toString());
    Assert.assertEquals(0, bpRecord2.getNumberOfAssignedChannels());
    Assert.assertEquals(BounceProxyRecord.ASSIGNMENT_TIMESTAMP_NEVER, bpRecord2.getLastAssignedTimestamp());
    Assert.assertEquals(2000l, bpRecord2.getFreshness().getTime());
    Assert.assertEquals(BounceProxyStatus.ALIVE, bpRecord2.getStatus());
}
Also used : BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Test(org.junit.Test)

Example 23 with BounceProxyRecord

use of io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord in project joynr by bmwcarit.

the class DatabasesTest method testUpdateChannelAssignment.

@Test
public void testUpdateChannelAssignment() {
    ControlledBounceProxyInformation bpInfo1 = new ControlledBounceProxyInformation("bp1.0", URI.create("http://www.joynr1.de/bp1/"));
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(1000l);
    bounceProxyDb.addBounceProxy(bpInfo1);
    channelDb.addChannel(new Channel(bpInfo1, "channel-123", URI.create("http://www.joyn1.de/bp1/channels/channel-123")));
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(2000l);
    bounceProxyDb.updateChannelAssignment("channel-123", bpInfo1);
    List<BounceProxyRecord> assignableBounceProxies = bounceProxyDb.getAssignableBounceProxies();
    Assert.assertEquals(1, assignableBounceProxies.size());
    BounceProxyRecord bpRecord1 = assignableBounceProxies.get(0);
    Assert.assertEquals("bp1.0", bpRecord1.getBounceProxyId());
    Assert.assertEquals(1, bpRecord1.getNumberOfAssignedChannels());
}
Also used : BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord) Channel(io.joynr.messaging.info.Channel) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Test(org.junit.Test)

Example 24 with BounceProxyRecord

use of io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord in project joynr by bmwcarit.

the class DatabasesTest method testUpdateBounceProxy.

@Test
public void testUpdateBounceProxy() {
    ControlledBounceProxyInformation bpInfo1 = new ControlledBounceProxyInformation("bp1.0", URI.create("http://www.joynr1.de/bp1/"));
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(1000l);
    bounceProxyDb.addBounceProxy(bpInfo1);
    BounceProxyRecord bpRecord = new BounceProxyRecord(bpInfo1);
    bpRecord.setFreshness(6000l);
    bpRecord.setLastAssignedTimestamp(4000l);
    bpRecord.setStatus(BounceProxyStatus.ACTIVE);
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(2000l);
    bounceProxyDb.updateBounceProxy(bpRecord);
    List<BounceProxyRecord> assignableBounceProxies = bounceProxyDb.getAssignableBounceProxies();
    Assert.assertEquals(1, assignableBounceProxies.size());
    BounceProxyRecord resultRecord = bounceProxyDb.getBounceProxy("bp1.0");
    Assert.assertEquals("bp1.0", resultRecord.getBounceProxyId());
    Assert.assertEquals(2000l, resultRecord.getFreshness().getTime());
    Assert.assertEquals(4000l, resultRecord.getLastAssignedTimestamp());
    Assert.assertEquals(BounceProxyStatus.ACTIVE, resultRecord.getStatus());
}
Also used : BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Test(org.junit.Test)

Example 25 with BounceProxyRecord

use of io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord in project joynr by bmwcarit.

the class BounceProxyDatabase method addBounceProxy.

@Override
public void addBounceProxy(ControlledBounceProxyInformation bpInfo) throws IllegalArgumentException {
    logger.trace("addBounceProxy(bpid={})", bpInfo.getId());
    BounceProxyRecord record = new BounceProxyRecord(bpInfo);
    record.setFreshness(timestampProvider.getCurrentTime());
    BounceProxyEntity bpEntity = new BounceProxyEntity(record);
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        em.persist(bpEntity);
        tx.commit();
    } catch (RuntimeException ex) {
        logger.error("Bounce proxy {} could not be persisted. error: {}", bpInfo.getId(), ex.getMessage());
        if (tx != null && tx.isActive())
            tx.rollback();
        throw ex;
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) BounceProxyEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity) BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord)

Aggregations

BounceProxyRecord (io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord)30 ControlledBounceProxyInformation (io.joynr.messaging.info.ControlledBounceProxyInformation)17 Test (org.junit.Test)16 LinkedList (java.util.LinkedList)6 BounceProxyInformation (io.joynr.messaging.info.BounceProxyInformation)4 BounceProxyStatusInformation (io.joynr.messaging.info.BounceProxyStatusInformation)4 Cache (net.sf.ehcache.Cache)3 Element (net.sf.ehcache.Element)3 BounceProxyEntity (io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity)2 BounceProxyStatus (io.joynr.messaging.info.BounceProxyStatus)2 Channel (io.joynr.messaging.info.Channel)1 PerformanceMeasures (io.joynr.messaging.info.PerformanceMeasures)1 List (java.util.List)1 EntityManager (javax.persistence.EntityManager)1 EntityTransaction (javax.persistence.EntityTransaction)1