public void testForStaleCheckWhenRegistryFull() throws Exception {
long startTimeStamp = System.currentTimeMillis() - 60000;
String markup = "<aura:component> %s </aura:component>";
DefDescriptor<ComponentDef> dd = addSourceAutoCleanup(ComponentDef.class, String.format(markup, ""));
((StringSource<?>) getSource(dd)).setLastModified(startTimeStamp);
ComponentDef initialDef = dd.getDef();
long initialTimeStamp = initialDef.getLocation().getLastModified();
assertEquals(startTimeStamp, initialTimeStamp);
fillCachingDefRegistryForComponents();
// Have to stop and start context because a given def is cached in MasterDefRegistry per request (context of the
// request)
Aura.getContextService().endContext();
Aura.getContextService().startContext(Mode.PROD, null, Format.JSON, Authentication.UNAUTHENTICATED, laxSecurityApp);
StringSource<?> source = (StringSource<?>) getSource(dd);
source.addOrUpdate(String.format(markup, "<aura:attribute type=\"String\" name=\"attr\"/>"));
source.setLastModified(startTimeStamp + 5);
// Verify that the initial def object hasn't been updated
assertEquals(initialTimeStamp, initialDef.getLocation().getLastModified());
// Fetch the def
assertTrue(Aura.getContextService().getCurrentContext().getDefRegistry().exists(dd));
ComponentDef updatedDef = dd.getDef();
// Verify that stale check has been performed
long updatedTimeStamp = updatedDef.getLocation().getLastModified();
assertEquals("Time stamp on def should have been updated", startTimeStamp + 5, updatedTimeStamp);
assertTrue(updatedDef instanceof BaseComponentDefImpl);
BaseComponentDefImpl<?> def = (BaseComponentDefImpl<?>) updatedDef;
assertNotNull("Failed to obtain the updated component Def", def.getAttributeDef("attr"));
}