use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class WallClockTimestampTest method testKryoSerializable.
@Test
public final void testKryoSerializable() {
WallClockTimestamp ts1 = new WallClockTimestamp();
WallClockTimestamp ts2 = new WallClockTimestamp(System.currentTimeMillis() + 10000);
final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
final KryoNamespace kryos = KryoNamespace.newBuilder().register(WallClockTimestamp.class).build();
kryos.serialize(ts1, buffer);
buffer.flip();
Timestamp copy = kryos.deserialize(buffer);
new EqualsTester().addEqualityGroup(ts1, copy).addEqualityGroup(ts2).testEquals();
}
use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class IntentCleanupTestMock method skipPoll.
/**
* Only submit one of two intents because one is too new.
*/
@Test
public void skipPoll() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
intentData.setState(CORRUPT);
store.write(intentData);
}
@Override
public void notify(IntentEvent event) {
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, null);
store.addPending(data);
Intent intent2 = new MockIntent(2L);
Timestamp version = new SystemClockTimestamp(1L);
data = new IntentData(intent2, INSTALL_REQ, version);
store.addPending(data);
service.submit(intent);
expectLastCall().once();
service.submit(intent2);
expectLastCall().once();
replay(service);
cleanup.run();
verify(service);
reset(service);
}
use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class IntentCleanupTestMock method installingPoll.
/**
* Trigger resubmit of intent in INSTALLING for too long.
*/
@Test
@Ignore("The implementation is dependent on the SimpleStore")
public void installingPoll() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
intentData.setState(INSTALLING);
store.write(intentData);
}
@Override
public void notify(IntentEvent event) {
cleanup.event(event);
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
Timestamp version = new SystemClockTimestamp(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, version);
store.addPending(data);
service.addPending(data);
expectLastCall().once();
replay(service);
cleanup.run();
verify(service);
reset(service);
}
use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class IntentCleanupTest method pendingPoll.
/**
* Trigger resubmit of intent in INSTALL_REQ for too long.
*/
@Test
public void pendingPoll() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
}
@Override
public void notify(IntentEvent event) {
cleanup.event(event);
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
Timestamp version = new SystemClockTimestamp(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, version);
store.addPending(data);
cleanup.run();
assertEquals("Expect number of submits incorrect", 1, service.pendingCounter());
}
use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class GossipDeviceStore method removeDeviceInternal.
private DeviceEvent removeDeviceInternal(DeviceId deviceId, Timestamp timestamp) {
Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptionsMap(deviceId);
synchronized (descs) {
// accept removal request if given timestamp is newer than
// the latest Timestamp from Primary provider
DeviceDescriptions primDescs = getPrimaryDescriptions(descs);
if (primDescs == null) {
return null;
}
Timestamp lastTimestamp = primDescs.getLatestTimestamp();
// If no timestamp is set, default the timestamp to the last timestamp for the device.
if (timestamp == null) {
timestamp = lastTimestamp;
}
if (timestamp.compareTo(lastTimestamp) <= 0) {
// outdated event ignore
return null;
}
removalRequest.put(deviceId, timestamp);
Device device = devices.remove(deviceId);
// removing internal description
deviceDescs.remove(deviceId);
// should DEVICE_REMOVED carry removed ports?
Map<PortNumber, Port> ports = devicePorts.get(deviceId);
if (ports != null) {
ports.clear();
}
markOfflineInternal(deviceId, timestamp);
descs.clear();
// Forget about the device
offline.remove(deviceId);
return device == null ? null : new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, device, null);
}
}
Aggregations