Search in sources :

Example 1 with ContextFunction

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);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 2 with ContextFunction

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);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 3 with ContextFunction

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);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 4 with ContextFunction

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);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 5 with ContextFunction

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]);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Aggregations

ContextFunction (org.eclipse.e4.core.contexts.ContextFunction)17 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)17 Test (org.junit.Test)14 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)3 RunAndTrack (org.eclipse.e4.core.contexts.RunAndTrack)2