Changing Intent Ids to use explicit id assignment
Change-Id: I5a4bff87842c37a869e7691b353529eaefc929db
diff --git a/core/net/src/test/java/org/onlab/onos/core/impl/DummyIdBlockAllocator.java b/core/net/src/test/java/org/onlab/onos/core/impl/DummyIdBlockAllocator.java
new file mode 100644
index 0000000..d4c0e64
--- /dev/null
+++ b/core/net/src/test/java/org/onlab/onos/core/impl/DummyIdBlockAllocator.java
@@ -0,0 +1,33 @@
+package org.onlab.onos.core.impl;
+
+import org.onlab.onos.core.IdBlock;
+
+public class DummyIdBlockAllocator implements IdBlockAllocator {
+ private long blockTop;
+ private static final long BLOCK_SIZE = 0x1000000L;
+
+ /**
+ * Returns a block of IDs which are unique and unused.
+ * Range of IDs is fixed size and is assigned incrementally as this method
+ * called.
+ *
+ * @return an IdBlock containing a set of unique IDs
+ */
+ @Override
+ public IdBlock allocateUniqueIdBlock() {
+ synchronized (this) {
+ long blockHead = blockTop;
+ long blockTail = blockTop + BLOCK_SIZE;
+
+ IdBlock block = new IdBlock(blockHead, BLOCK_SIZE);
+ blockTop = blockTail;
+
+ return block;
+ }
+ }
+
+ @Override
+ public IdBlock allocateUniqueIdBlock(long range) {
+ throw new UnsupportedOperationException("Not supported yet");
+ }
+}
diff --git a/core/net/src/test/java/org/onlab/onos/core/impl/IdBlockAllocatorBasedIdGeneratorTest.java b/core/net/src/test/java/org/onlab/onos/core/impl/IdBlockAllocatorBasedIdGeneratorTest.java
new file mode 100644
index 0000000..07d30ca
--- /dev/null
+++ b/core/net/src/test/java/org/onlab/onos/core/impl/IdBlockAllocatorBasedIdGeneratorTest.java
@@ -0,0 +1,43 @@
+package org.onlab.onos.core.impl;
+
+import org.easymock.EasyMock;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.onos.core.IdBlock;
+
+/**
+ * Suites of test of {@link org.onlab.onos.core.impl.BlockAllocatorBasedIdGenerator}.
+ */
+public class IdBlockAllocatorBasedIdGeneratorTest {
+ private IdBlockAllocator allocator;
+ private BlockAllocatorBasedIdGenerator sut;
+
+ @Before
+ public void setUp() {
+ allocator = EasyMock.createMock(IdBlockAllocator.class);
+
+ }
+
+ /**
+ * Tests generated IntentId sequences using two {@link org.onlab.onos.core.IdBlock blocks}.
+ */
+ @Test
+ public void testIds() {
+ EasyMock.expect(allocator.allocateUniqueIdBlock())
+ .andReturn(new IdBlock(0, 3))
+ .andReturn(new IdBlock(4, 3));
+
+ EasyMock.replay(allocator);
+ sut = new BlockAllocatorBasedIdGenerator(allocator);
+
+ Assert.assertThat(sut.getNewId(), Matchers.is(0L));
+ Assert.assertThat(sut.getNewId(), Matchers.is(1L));
+ Assert.assertThat(sut.getNewId(), Matchers.is(2L));
+
+ Assert.assertThat(sut.getNewId(), Matchers.is(4L));
+ Assert.assertThat(sut.getNewId(), Matchers.is(5L));
+ Assert.assertThat(sut.getNewId(), Matchers.is(6L));
+ }
+}
diff --git a/core/net/src/test/java/org/onlab/onos/core/impl/TestCoreManager.java b/core/net/src/test/java/org/onlab/onos/core/impl/TestCoreManager.java
new file mode 100644
index 0000000..7b5fbb2
--- /dev/null
+++ b/core/net/src/test/java/org/onlab/onos/core/impl/TestCoreManager.java
@@ -0,0 +1,36 @@
+package org.onlab.onos.core.impl;
+
+import org.onlab.onos.core.ApplicationId;
+import org.onlab.onos.core.CoreService;
+import org.onlab.onos.core.IdGenerator;
+import org.onlab.onos.core.Version;
+
+import java.util.Set;
+
+public class TestCoreManager implements CoreService {
+ @Override
+ public Version version() {
+ return null;
+ }
+
+ @Override
+ public Set<ApplicationId> getAppIds() {
+ return null;
+ }
+
+ @Override
+ public ApplicationId getAppId(Short id) {
+ return null;
+ }
+
+ @Override
+ public ApplicationId registerApplication(String identifier) {
+ return null;
+ }
+
+ @Override
+ public IdGenerator getIdGenerator(String topic) {
+ IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
+ return new BlockAllocatorBasedIdGenerator(idBlockAllocator);
+ }
+}