Search in sources :

Example 56 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class GMSJoinLeaveTestHelper method getGmsJoinLeave.

private static GMSJoinLeave getGmsJoinLeave() {
    InternalDistributedSystem distributedSystem = getInternalDistributedSystem();
    DM dm = distributedSystem.getDM();
    GMSMembershipManager membershipManager = (GMSMembershipManager) dm.getMembershipManager();
    Services services = membershipManager.getServices();
    return (GMSJoinLeave) services.getJoinLeave();
}
Also used : Services(org.apache.geode.distributed.internal.membership.gms.Services) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) DM(org.apache.geode.distributed.internal.DM) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 57 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class GemFireCacheImplTest method checkEvictorsClosed.

@Test
public void checkEvictorsClosed() {
    InternalDistributedSystem ds = Fakes.distributedSystem();
    CacheConfig cc = new CacheConfig();
    TypeRegistry typeRegistry = mock(TypeRegistry.class);
    SystemTimer ccpTimer = mock(SystemTimer.class);
    HeapEvictor he = mock(HeapEvictor.class);
    OffHeapEvictor ohe = mock(OffHeapEvictor.class);
    GemFireCacheImpl gfc = GemFireCacheImpl.createWithAsyncEventListeners(ds, cc, typeRegistry);
    try {
        gfc.setHeapEvictor(he);
        gfc.setOffHeapEvictor(ohe);
    } finally {
        gfc.close();
    }
    verify(he, times(1)).close();
    verify(ohe, times(1)).close();
}
Also used : OffHeapEvictor(org.apache.geode.internal.cache.lru.OffHeapEvictor) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) HeapEvictor(org.apache.geode.internal.cache.lru.HeapEvictor) OffHeapEvictor(org.apache.geode.internal.cache.lru.OffHeapEvictor) SystemTimer(org.apache.geode.internal.SystemTimer) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 58 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class GemFireCacheImplTest method checkThatAsyncEventListenersUseAllThreadsInPool.

@Test
public void checkThatAsyncEventListenersUseAllThreadsInPool() {
    InternalDistributedSystem ds = Fakes.distributedSystem();
    CacheConfig cc = new CacheConfig();
    TypeRegistry typeRegistry = mock(TypeRegistry.class);
    GemFireCacheImpl gfc = GemFireCacheImpl.createWithAsyncEventListeners(ds, cc, typeRegistry);
    try {
        ThreadPoolExecutor executor = (ThreadPoolExecutor) gfc.getEventThreadPool();
        assertEquals(0, executor.getCompletedTaskCount());
        assertEquals(0, executor.getActiveCount());
        int MAX_THREADS = GemFireCacheImpl.EVENT_THREAD_LIMIT;
        final CountDownLatch cdl = new CountDownLatch(MAX_THREADS);
        for (int i = 1; i <= MAX_THREADS; i++) {
            executor.execute(() -> {
                cdl.countDown();
                try {
                    cdl.await();
                } catch (InterruptedException e) {
                }
            });
        }
        Awaitility.await().pollInterval(10, TimeUnit.MILLISECONDS).pollDelay(10, TimeUnit.MILLISECONDS).timeout(90, TimeUnit.SECONDS).until(() -> assertEquals(MAX_THREADS, executor.getCompletedTaskCount()));
    } finally {
        gfc.close();
    }
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 59 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class PRFunctionExecutionDUnitTest method bug41118.

public static void bug41118() {
    InternalDistributedSystem ds = new PRFunctionExecutionDUnitTest().getSystem();
    assertNotNull(ds);
    ds.disconnect();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    ds = (InternalDistributedSystem) DistributedSystem.connect(props);
    DM dm = ds.getDistributionManager();
    assertEquals("Distributed System is not loner", true, dm instanceof LonerDistributionManager);
    Cache cache = CacheFactory.create(ds);
    AttributesFactory factory = new AttributesFactory();
    factory.setDataPolicy(DataPolicy.PARTITION);
    assertNotNull(cache);
    Region region = cache.createRegion("PartitonedRegion", factory.create());
    for (int i = 0; i < 20; i++) {
        region.put("KEY_" + i, "VALUE_" + i);
    }
    Set<String> keysForGet = new HashSet<String>();
    keysForGet.add("KEY_4");
    keysForGet.add("KEY_9");
    keysForGet.add("KEY_7");
    try {
        Execution execution = FunctionService.onRegion(region).withFilter(keysForGet).setArguments(Boolean.TRUE);
        ResultCollector rc = execution.execute(new FunctionAdapter() {

            @Override
            public void execute(FunctionContext fc) {
                RegionFunctionContext context = (RegionFunctionContext) fc;
                Set keys = context.getFilter();
                Set keysTillSecondLast = new HashSet();
                int setSize = keys.size();
                Iterator keysIterator = keys.iterator();
                for (int i = 0; i < (setSize - 1); i++) {
                    keysTillSecondLast.add(keysIterator.next());
                }
                for (Object k : keysTillSecondLast) {
                    context.getResultSender().sendResult((Serializable) PartitionRegionHelper.getLocalDataForContext(context).get(k));
                }
                Object lastResult = keysIterator.next();
                context.getResultSender().lastResult((Serializable) PartitionRegionHelper.getLocalDataForContext(context).get(lastResult));
            }

            @Override
            public String getId() {
                return getClass().getName();
            }
        });
        rc.getResult();
        ds.disconnect();
    } catch (Exception e) {
        LogWriterUtils.getLogWriter().info("Exception Occurred : " + e.getMessage());
        e.printStackTrace();
        Assert.fail("Test failed", e);
    }
}
Also used : Serializable(java.io.Serializable) LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) Set(java.util.Set) HashSet(java.util.HashSet) DM(org.apache.geode.distributed.internal.DM) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) FunctionContext(org.apache.geode.cache.execute.FunctionContext) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionException(org.apache.geode.cache.execute.FunctionException) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) Execution(org.apache.geode.cache.execute.Execution) Iterator(java.util.Iterator) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LonerDistributionManager(org.apache.geode.distributed.internal.LonerDistributionManager) ResultCollector(org.apache.geode.cache.execute.ResultCollector) Cache(org.apache.geode.cache.Cache) HashSet(java.util.HashSet)

Example 60 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class MsgDestreamer method getLogger.

private static LogWriterI18n getLogger() {
    LogWriterI18n result = null;
    InternalDistributedSystem ids = InternalDistributedSystem.unsafeGetConnectedInstance();
    if (ids != null) {
        result = ids.getLogWriter().convertToLogWriterI18n();
    }
    return result;
}
Also used : LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Aggregations

InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)209 Properties (java.util.Properties)70 Test (org.junit.Test)60 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)58 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)41 IOException (java.io.IOException)35 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)32 DM (org.apache.geode.distributed.internal.DM)30 File (java.io.File)22 HashSet (java.util.HashSet)21 Set (java.util.Set)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)19 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)19 Region (org.apache.geode.cache.Region)17 ArrayList (java.util.ArrayList)16 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)16 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)14 VM (org.apache.geode.test.dunit.VM)14 Cache (org.apache.geode.cache.Cache)13 IgnoredException (org.apache.geode.test.dunit.IgnoredException)13