Search in sources :

Example 1 with LifecycleEventType

use of org.apache.ignite.lifecycle.LifecycleEventType in project ignite by apache.

the class GridLifecycleBeanSelfTest method testGetIgnite.

/**
     * @throws Exception If failed.
     */
public void testGetIgnite() throws Exception {
    final AtomicBoolean done = new AtomicBoolean();
    bean = new LifeCycleBaseBean() {

        /** */
        @IgniteInstanceResource
        private Ignite ignite;

        @Override
        public void onLifecycleEvent(LifecycleEventType evt) {
            super.onLifecycleEvent(evt);
            if (evt == LifecycleEventType.AFTER_NODE_START) {
                Ignite ignite0 = Ignition.ignite(ignite.name());
                assertNotNull(ignite0);
                assertNotNull(ignite0.cluster().localNode());
                done.set(true);
            }
        }
    };
    try {
        startGrid();
        assertTrue(done.get());
    } finally {
        stopAllGrids();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) Ignite(org.apache.ignite.Ignite) LifecycleEventType(org.apache.ignite.lifecycle.LifecycleEventType)

Example 2 with LifecycleEventType

use of org.apache.ignite.lifecycle.LifecycleEventType in project ignite by apache.

the class GridCacheDhtPreloadUnloadSelfTest method testUnloadOneBackThreeNodesWithLifeCycleBean.

/** @throws Exception If failed. */
public void testUnloadOneBackThreeNodesWithLifeCycleBean() throws Exception {
    preloadMode = SYNC;
    backups = 1;
    try {
        final int cnt = 1000;
        lbean = new LifecycleBean() {

            @IgniteInstanceResource
            private Ignite ignite;

            @Override
            public void onLifecycleEvent(LifecycleEventType evt) {
                if (evt == LifecycleEventType.AFTER_NODE_START) {
                    IgniteCache<Integer, String> c = ignite.cache(DEFAULT_CACHE_NAME);
                    if (c.putIfAbsent(-1, "true")) {
                        populate(ignite.<Integer, String>cache(DEFAULT_CACHE_NAME), cnt);
                        info(">>> POPULATED GRID <<<");
                    }
                }
            }
        };
        int gridCnt = 3;
        for (int i = 0; i < gridCnt; i++) {
            startGrid(i);
            for (int j = 0; j < i; j++) info("Grid size [i=" + i + ", size=" + grid(j).cache(DEFAULT_CACHE_NAME).localSize() + ']');
        }
        long wait = 3000;
        waitForUnload(gridCnt, cnt, wait);
    } finally {
        lbean = null;
        stopAllGrids();
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteCache(org.apache.ignite.IgniteCache) LifecycleBean(org.apache.ignite.lifecycle.LifecycleBean) Ignite(org.apache.ignite.Ignite) LifecycleEventType(org.apache.ignite.lifecycle.LifecycleEventType)

Example 3 with LifecycleEventType

use of org.apache.ignite.lifecycle.LifecycleEventType in project ignite by apache.

the class GridCacheDhtPreloadBigDataSelfTest method testLargeObjectsWithLifeCycleBean.

/**
     * @throws Exception If failed.
     */
public void testLargeObjectsWithLifeCycleBean() throws Exception {
    preloadMode = SYNC;
    partitions = 23;
    try {
        final int cnt = 10000;
        lbean = new LifecycleBean() {

            @IgniteInstanceResource
            private Ignite ignite;

            @Override
            public void onLifecycleEvent(LifecycleEventType evt) {
                if (evt == LifecycleEventType.AFTER_NODE_START) {
                    IgniteCache<Integer, byte[]> c = ignite.cache(DEFAULT_CACHE_NAME);
                    if (c.putIfAbsent(-1, new byte[1])) {
                        populate(c, cnt, KBSIZE);
                        info(">>> POPULATED GRID <<<");
                    }
                }
            }
        };
        int gridCnt = 3;
        for (int i = 0; i < gridCnt; i++) startGrid(i);
        for (int i = 0; i < gridCnt; i++) info("Grid size [i=" + i + ", size=" + grid(i).cache(DEFAULT_CACHE_NAME).size() + ']');
        Thread.sleep(10000);
        for (int i = 0; i < gridCnt; i++) {
            IgniteCache<Integer, String> c = grid(i).cache(DEFAULT_CACHE_NAME);
            if (backups + 1 <= gridCnt)
                assert c.localSize() < cnt;
            else
                assert c.localSize() == cnt;
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteCache(org.apache.ignite.IgniteCache) LifecycleBean(org.apache.ignite.lifecycle.LifecycleBean) Ignite(org.apache.ignite.Ignite) LifecycleEventType(org.apache.ignite.lifecycle.LifecycleEventType)

Aggregations

Ignite (org.apache.ignite.Ignite)3 LifecycleEventType (org.apache.ignite.lifecycle.LifecycleEventType)3 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)3 IgniteCache (org.apache.ignite.IgniteCache)2 LifecycleBean (org.apache.ignite.lifecycle.LifecycleBean)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1