Search in sources :

Example 41 with ControlledBounceProxyInformation

use of io.joynr.messaging.info.ControlledBounceProxyInformation in project joynr by bmwcarit.

the class DatabasesTest method testCascadingDelete.

@Test
@Ignore
public void testCascadingDelete() {
    Assert.assertEquals(0, channelDb.getChannels().size());
    ControlledBounceProxyInformation bpInfo = new ControlledBounceProxyInformation("bp1.0", URI.create("http://www.joynr1.de/bp1/"));
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(1000l);
    bounceProxyDb.addBounceProxy(bpInfo);
    channelDb.addChannel(new Channel(bpInfo, "channel1", URI.create("http://www.joyn1.de/bp1/channels/channel1")));
    Assert.assertEquals(1, bounceProxyDb.getAssignableBounceProxies().size());
    Assert.assertEquals(1, channelDb.getChannels().size());
    // delete bounce proxy
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    tx.begin();
    Query deleteBounceProxiesQuery = em.createQuery("DELETE FROM BounceProxyEntity");
    Assert.assertEquals(3, deleteBounceProxiesQuery.executeUpdate());
    tx.commit();
    Assert.assertEquals(0, bounceProxyDb.getAssignableBounceProxies().size());
    Assert.assertEquals(0, channelDb.getChannels().size());
    tx.begin();
    Query deleteBounceProxyInformationQuery = em.createQuery("DELETE FROM BounceProxyInformationEntity");
    Assert.assertEquals(0, deleteBounceProxyInformationQuery.executeUpdate());
    Query deleteChannelsQuery = em.createQuery("DELETE FROM ChannelEntity");
    Assert.assertEquals(0, deleteChannelsQuery.executeUpdate());
    tx.commit();
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) Channel(io.joynr.messaging.info.Channel) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 42 with ControlledBounceProxyInformation

use of io.joynr.messaging.info.ControlledBounceProxyInformation 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 43 with ControlledBounceProxyInformation

use of io.joynr.messaging.info.ControlledBounceProxyInformation 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 44 with ControlledBounceProxyInformation

use of io.joynr.messaging.info.ControlledBounceProxyInformation in project joynr by bmwcarit.

the class InMemoryBounceProxyDirectoryTest method testUpdateBounceProxy.

@Test
public void testUpdateBounceProxy() {
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(100l);
    directory.addBounceProxy(new ControlledBounceProxyInformation("X.Y", URI.create("http://www.location.de")));
    BounceProxyRecord bounceProxyRecord = directory.getBounceProxy("X.Y");
    bounceProxyRecord.getInfo().setLocation(URI.create("http://www.location-updated.de"));
    bounceProxyRecord.getInfo().setLocationForBpc(URI.create("http://www.location-for-bpc-updated.de"));
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(200l);
    directory.updateBounceProxy(bounceProxyRecord);
    BounceProxyRecord result = directory.getBounceProxy("X.Y");
    assertEquals("http://www.location-updated.de", result.getInfo().getLocation().toString());
    assertEquals("http://www.location-for-bpc-updated.de", result.getInfo().getLocationForBpc().toString());
    assertEquals(200, result.getFreshness().getTime());
}
Also used : ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Test(org.junit.Test)

Example 45 with ControlledBounceProxyInformation

use of io.joynr.messaging.info.ControlledBounceProxyInformation in project joynr by bmwcarit.

the class InMemoryBounceProxyDirectoryTest method testUpdateChannelAssignment.

@Test
public void testUpdateChannelAssignment() {
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(100l);
    directory.addBounceProxy(new ControlledBounceProxyInformation("X.Y", null));
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(200l);
    directory.updateChannelAssignment("channel-123", new BounceProxyInformation("X.Y", null));
    BounceProxyRecord bounceProxy = directory.getBounceProxy("X.Y");
    assertNotNull(bounceProxy);
    assertEquals(1, bounceProxy.getNumberOfAssignedChannels());
    assertEquals(200, bounceProxy.getLastAssignedTimestamp());
}
Also used : ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) BounceProxyInformation(io.joynr.messaging.info.BounceProxyInformation) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Test(org.junit.Test)

Aggregations

ControlledBounceProxyInformation (io.joynr.messaging.info.ControlledBounceProxyInformation)47 Test (org.junit.Test)44 BounceProxyRecord (io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord)13 IsCreateChannelHttpRequest (io.joynr.messaging.bounceproxy.IsCreateChannelHttpRequest)5 JoynrProtocolException (io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException)5 BounceProxyStatusInformation (io.joynr.messaging.info.BounceProxyStatusInformation)5 Channel (io.joynr.messaging.info.Channel)5 HttpResponse (org.apache.http.HttpResponse)5 HttpContext (org.apache.http.protocol.HttpContext)5 URI (java.net.URI)4 BounceProxyInformation (io.joynr.messaging.info.BounceProxyInformation)2 BounceProxyStatus (io.joynr.messaging.info.BounceProxyStatus)2 PerformanceMeasures (io.joynr.messaging.info.PerformanceMeasures)2 JoynrCommunicationException (io.joynr.exceptions.JoynrCommunicationException)1 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 IOException (java.io.IOException)1 EntityManager (javax.persistence.EntityManager)1 EntityTransaction (javax.persistence.EntityTransaction)1 Query (javax.persistence.Query)1 HttpException (org.apache.http.HttpException)1