Search in sources :

Example 1 with BounceProxyRecord

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

the class BounceProxyEhcacheAdapter method getBounceProxyRecordFromElement.

protected BounceProxyRecord getBounceProxyRecordFromElement(Element element) {
    BounceProxyRecord bpRecord = (BounceProxyRecord) element.getObjectValue();
    bpRecord.setFreshness(element.getLatestOfCreationAndUpdateTime());
    return bpRecord;
}
Also used : BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord)

Example 2 with BounceProxyRecord

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

the class BounceProxyEhcacheAdapter method updateChannelAssignment.

@Override
public void updateChannelAssignment(String ccid, BounceProxyInformation bpInfo) throws IllegalArgumentException {
    if (log.isTraceEnabled()) {
        log.trace("Update channel assignment for bounce proxy {} in cache {}", bpInfo.getId(), cacheName);
        tracePeers();
    }
    Cache cache = manager.getCache(cacheName);
    Element element = cache.get(bpInfo.getId());
    if (element == null) {
        throw new IllegalArgumentException("No bounce proxy with ID '" + bpInfo.getId() + "' exists");
    }
    BounceProxyRecord bpRecord = getBounceProxyRecordFromElement(element);
    bpRecord.addAssignedChannel(ccid);
    Element updatedElement = new Element(bpInfo.getId(), bpRecord);
    cache.put(updatedElement);
}
Also used : BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord) Element(net.sf.ehcache.Element) Cache(net.sf.ehcache.Cache)

Example 3 with BounceProxyRecord

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

the class RoundRobinAssignmentTest method testAssignmentToUnassignedBounceProxySmallTimestamps.

@Test
public void testAssignmentToUnassignedBounceProxySmallTimestamps() {
    LinkedList<BounceProxyRecord> bpList = new LinkedList<BounceProxyRecord>();
    bpList.add(createBounceProxyRecordWithChannels("X1.Y1", 2, 2l));
    bpList.add(createBounceProxyRecordWithChannels("X2.Y2", 3, 3l));
    bpList.add(createBounceProxyRecord("X3.Y3"));
    Mockito.when(directoryMock.getAssignableBounceProxies()).thenReturn(bpList);
    BounceProxyInformation bounceProxy = assignmentStrategy.calculateBounceProxy("channel-123");
    Assert.assertEquals("X3.Y3", bounceProxy.getId());
    Mockito.verify(directoryMock, Mockito.never()).updateChannelAssignment("channel-123", bounceProxy);
}
Also used : BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord) BounceProxyInformation(io.joynr.messaging.info.BounceProxyInformation) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with BounceProxyRecord

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

the class RoundRobinAssignmentTest method testAssignmentToUnassignedBounceProxy.

@Test
public void testAssignmentToUnassignedBounceProxy() {
    LinkedList<BounceProxyRecord> bpList = new LinkedList<BounceProxyRecord>();
    bpList.add(createBounceProxyRecordWithChannels("X1.Y1", 2, 23456456456l));
    bpList.add(createBounceProxyRecordWithChannels("X2.Y2", 3, 19837453453l));
    bpList.add(createBounceProxyRecord("X3.Y3"));
    Mockito.when(directoryMock.getAssignableBounceProxies()).thenReturn(bpList);
    BounceProxyInformation bounceProxy = assignmentStrategy.calculateBounceProxy("channel-123");
    Assert.assertEquals("X3.Y3", bounceProxy.getId());
    Mockito.verify(directoryMock, Mockito.never()).updateChannelAssignment("channel-123", bounceProxy);
}
Also used : BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord) BounceProxyInformation(io.joynr.messaging.info.BounceProxyInformation) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with BounceProxyRecord

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

the class RoundRobinAssignmentTest method createBounceProxyRecordWithChannels.

private BounceProxyRecord createBounceProxyRecordWithChannels(String bpId, int noOfAssignedChannels, long lastAssignedTimestamp) {
    BounceProxyRecord record = createBounceProxyRecord(bpId);
    for (int i = 0; i < noOfAssignedChannels; i++) {
        record.addAssignedChannel("channel-" + bpId + "-" + 1);
    }
    record.setLastAssignedTimestamp(lastAssignedTimestamp);
    return record;
}
Also used : 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