use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ContextPerformanceTest method testSetValueRunAndTrack.
/**
* Tests setting a value in a context that a RAT is listening to. This test mimics what occurs
* when handlers change in e4. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=305038
*/
public void testSetValueRunAndTrack() {
context.set("somefunction", new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
// make sure this function has a large number of dependencies
for (int i = 0; i < 1000; i++) {
context.get("NonExistentValue-" + i);
}
return context.get("something");
}
});
context.runAndTrack(new RunAndTrack() {
@Override
public boolean changed(IEclipseContext context) {
context.get("somefunction");
return true;
}
});
new PerformanceTestRunner() {
int i = 0;
@Override
protected void test() {
context.set("something", "value-" + i++);
}
}.run(this, 10, 400);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ContextPerformanceTest method testSetContextFunction.
public void testSetContextFunction() {
context.set("somefunction", new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return context.get("something");
}
});
new PerformanceTestRunner() {
int i = 0;
@Override
protected void test() {
context.set("something", "value-" + i++);
}
}.run(this, 10, 600000);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ContextPerformanceTest method testLookupContextFunction.
public void testLookupContextFunction() {
context.set("somefunction", new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return "result";
}
});
new PerformanceTestRunner() {
@Override
protected void test() {
context.get("somefunction");
}
}.run(this, 10, 5000000);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class InjectionUpdateTest method testNestedUpdatesConstructor.
@Test
public void testNestedUpdatesConstructor() throws Exception {
IEclipseContext appContext = EclipseContextFactory.create();
appContext.set(InjectTarget2.class.getName(), new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
return ContextInjectionFactory.make(InjectTarget2.class, context);
}
});
InjectTarget2 targetA = appContext.get(InjectTarget2.class);
targetA.modify();
InjectTarget2 targetB = appContext.get(InjectTarget2.class);
assertEquals(targetA, targetB);
assertSame(targetA, targetB);
}
use of org.eclipse.e4.core.contexts.ContextFunction in project eclipse.platform.runtime by eclipse.
the class ReparentingTest method testUpdateSameParentCalculated.
@Test
public void testUpdateSameParentCalculated() {
final int[] testServiceCount = new int[1];
testServiceCount[0] = 0;
IEclipseContext parentContext = EclipseContextFactory.create("parent");
parentContext.set(TestService.class.getName(), new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
testServiceCount[0]++;
return ContextInjectionFactory.make(TestService.class, context);
}
});
IEclipseContext childContext = parentContext.createChild("child");
childContext.get(TestService.class);
assertEquals(1, testServiceCount[0]);
childContext.setParent(childContext.getParent());
assertEquals(1, testServiceCount[0]);
}
Aggregations