Added code to intent unit tests to pre-emptively unbind ID generator to avoid cascading failures.

Change-Id: I2e5aff44a90ceeaaad71d7154b79f20edab620a7
This commit is contained in:
Thomas Vachuska 2017-02-03 11:44:15 -08:00
parent e538711b8d
commit 2323596967
24 changed files with 27 additions and 2 deletions

View File

@ -72,6 +72,7 @@ public class OpticalConnectivityTest {
}
};
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
}

View File

@ -248,6 +248,7 @@ public class OpticalPathProvisionerTest {
return counter++;
}
};
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
}

View File

@ -54,6 +54,7 @@ public class PacketLinkRealizedByOpticalTest {
}
};
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
}

View File

@ -377,6 +377,7 @@ public class OpticalCircuitIntentCompilerTest {
sut.intentService = new TestIntentService();
sut.intentSetMultimap = new MockIntentSetMultimap();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
intentExtensionService = createMock(IntentExtensionService.class);

View File

@ -274,6 +274,7 @@ public class OpticalOduIntentCompilerTest {
sut.resourceService = new MockResourceService();
sut.topologyService = new MockTopologyService();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
intentExtensionService = createMock(IntentExtensionService.class);

View File

@ -81,6 +81,7 @@ public class OpticalPathIntentCompilerTest {
.andReturn(appId);
sut.coreService = coreService;
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
intent = OpticalPathIntent.builder()

View File

@ -245,6 +245,7 @@ public class VplsTest {
@Before
public void setUp() throws Exception {
idGenerator = new TestIdGenerator();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
applicationService = createMock(ApplicationService.class);

View File

@ -55,6 +55,7 @@ public class IntentDataTest {
@Before
public void setUpTest() {
idGenerator = new MockIdGenerator();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
timestamp1 = new MockTimestamp(1);

View File

@ -47,6 +47,7 @@ public class IntentServiceTest {
public void setUp() {
service = createIntentService();
service.addListener(listener);
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
}

View File

@ -25,10 +25,13 @@ import java.util.concurrent.atomic.AtomicLong;
public class MockIdGenerator implements IdGenerator {
private static boolean generatorIsBound = false;
private static MockIdGenerator idGenerator;
public static void bindNewGenerator() {
if (!generatorIsBound) {
generatorIsBound = true;
Intent.bindIdGenerator(new MockIdGenerator());
idGenerator = new MockIdGenerator();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
}
}
private AtomicLong nextId = new AtomicLong(0);

View File

@ -167,6 +167,7 @@ public class IntentManager
batchExecutor = newSingleThreadExecutor(groupedThreads("onos/intent", "batch", log));
workerExecutor = newFixedThreadPool(numThreads, groupedThreads("onos/intent", "worker-%d", log));
idGenerator = coreService.getIdGenerator("intent-ids");
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
log.info("Started");
}

View File

@ -57,6 +57,7 @@ public class IntentAccumulatorTest {
@Before
public void localSetup() {
mockGenerator = new MockIdGenerator();
Intent.unbindIdGenerator(mockGenerator);
Intent.bindIdGenerator(mockGenerator);
intent1 = new MockIntent(1L);

View File

@ -89,13 +89,13 @@ public class IntentCleanupTest {
assertTrue("store should be empty",
Sets.newHashSet(cleanup.store.getIntents()).isEmpty());
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
}
@After
public void tearDown() {
cleanup.deactivate();
Intent.unbindIdGenerator(idGenerator);
}

View File

@ -72,6 +72,7 @@ public class IntentCleanupTestMock {
assertTrue("store should be empty",
Sets.newHashSet(cleanup.store.getIntents()).isEmpty());
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
}

View File

@ -89,6 +89,7 @@ public class ObjectiveTrackerTest {
deviceListener = TestUtils.getField(tracker, "deviceListener");
resourceListener = TestUtils.getField(tracker, "resourceListener");
mockGenerator = new MockIdGenerator();
Intent.unbindIdGenerator(mockGenerator);
Intent.bindIdGenerator(mockGenerator);
}

View File

@ -65,6 +65,7 @@ public class LinkCollectionEncapIntentCompilerTest extends AbstractLinkCollectio
expect(coreService.registerApplication("org.onosproject.net.intent")).andReturn(appId);
sut.coreService = coreService;
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
intentExtensionService = createMock(IntentExtensionService.class);

View File

@ -68,6 +68,7 @@ public class LinkCollectionIntentCompilerP2PTest extends AbstractLinkCollectionT
.andReturn(appId);
sut.coreService = coreService;
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
intentExtensionService = createMock(IntentExtensionService.class);

View File

@ -80,6 +80,7 @@ public class LinkCollectionIntentCompilerTest extends AbstractLinkCollectionTest
.andReturn(appId);
sut.coreService = coreService;
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
intent = LinkCollectionIntent.builder()

View File

@ -65,6 +65,7 @@ public class LinkCollectionOptimizationTest extends AbstractLinkCollectionTest {
.andReturn(appId);
sut.coreService = coreService;
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
intentExtensionService = createMock(IntentExtensionService.class);

View File

@ -98,6 +98,7 @@ public class MplsPathIntentCompilerTest {
sut.coreService = coreService;
sut.resourceService = new MockResourceService();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
intent = MplsPathIntent.builder()

View File

@ -176,6 +176,7 @@ public class PathIntentCompilerTest {
sut.coreService = coreService;
sut.resourceService = new MockResourceService();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
intent = PathIntent.builder()

View File

@ -88,6 +88,7 @@ public class CompilingTest {
idGenerator = new MockIdGenerator();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
// Intent creation should be placed after binding an ID generator

View File

@ -58,6 +58,7 @@ public class GossipIntentStoreTest {
intentStore.partitionService = new WorkPartitionServiceAdapter();
intentStore.clusterService = new ClusterServiceAdapter();
idGenerator = new MockIdGenerator();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
builder1 = HostToHostIntent
.builder()

View File

@ -92,6 +92,7 @@ public class VirtualNetworkManagerTest extends TestDeviceParams {
@Before
public void setUp() throws Exception {
virtualNetworkManagerStore = new DistributedVirtualNetworkStore();
Intent.unbindIdGenerator(idGenerator);
Intent.bindIdGenerator(idGenerator);
coreService = new TestCoreService();