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());
}
}
}
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());
}
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());
}
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());
}
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;
}
}
Aggregations