Search in sources :

Example 11 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry 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 12 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry 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 13 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.

the class DataTypeJUnitTest method getDataTypeShouldReturnPDXEnumType.

@Test
public void getDataTypeShouldReturnPDXEnumType() throws IOException {
    int somePdxEnumId = 1;
    EnumInfo somePdxEnumInfo = mock(EnumInfo.class);
    doReturn("PDXENUM").when(somePdxEnumInfo).getClassName();
    TypeRegistry mockTypeRegistry = mock(TypeRegistry.class);
    when(mockTypeRegistry.getEnumInfoById(0)).thenReturn(somePdxEnumInfo);
    GemFireCacheImpl pdxInstance = mock(GemFireCacheImpl.class);
    when(pdxInstance.getPdxRegistry()).thenReturn(mockTypeRegistry);
    PowerMockito.mockStatic(GemFireCacheImpl.class);
    when(GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.")).thenReturn(pdxInstance);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    out.writeByte(DSCODE.PDX_ENUM);
    out.writeInt(somePdxEnumId);
    byte[] bytes = baos.toByteArray();
    String type = DataType.getDataType(bytes);
    assertThat(type).isEqualTo("PdxRegistry/java.lang.Enum:PDXENUM");
}
Also used : DataOutputStream(java.io.DataOutputStream) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) UnitTest(org.apache.geode.test.junit.categories.UnitTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.

the class PdxTypeExportDUnitTest method testPeer.

@Test
public void testPeer() throws Exception {
    Region r = getCache().getRegion("pdxtest");
    r.get(1);
    TypeRegistry tr = ((GemFireCacheImpl) getCache()).getPdxRegistry();
    Collection<PdxType> types = tr.typeMap().values();
    assertEquals(MyObjectPdx.class.getName(), types.iterator().next().getClassName());
    Collection<EnumInfo> enums = tr.enumMap().values();
    assertEquals(MyEnumPdx.const1.name(), enums.iterator().next().getEnum().name());
}
Also used : MyObjectPdx(com.examples.snapshot.MyObjectPdx) PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 15 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.

the class PdxRegistryRecoveryListener method endpointNowInUse.

@Override
public void endpointNowInUse(Endpoint endpoint) {
    int count = endpointCount.incrementAndGet();
    if (logger.isDebugEnabled()) {
        logger.debug("PdxRegistryRecoveryListener - EndpointNowInUse. Now have {} endpoints", count);
    }
    if (count == 1) {
        InternalCache cache = GemFireCacheImpl.getInstance();
        if (cache == null) {
            return;
        }
        TypeRegistry registry = cache.getPdxRegistry();
        if (registry == null) {
            return;
        }
        registry.clear();
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry)

Aggregations

TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)24 InternalCache (org.apache.geode.internal.cache.InternalCache)10 PdxType (org.apache.geode.pdx.internal.PdxType)10 Test (org.junit.Test)10 IOException (java.io.IOException)7 EnumInfo (org.apache.geode.pdx.internal.EnumInfo)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)5 Message (org.apache.geode.internal.cache.tier.sockets.Message)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)3 CancelException (org.apache.geode.CancelException)2 GemFireRethrowable (org.apache.geode.GemFireRethrowable)2 ToDataException (org.apache.geode.ToDataException)2 SystemTimer (org.apache.geode.internal.SystemTimer)2 NonPortableClassException (org.apache.geode.pdx.NonPortableClassException)2 PdxInstance (org.apache.geode.pdx.PdxInstance)2 PdxInstanceImpl (org.apache.geode.pdx.internal.PdxInstanceImpl)2 PdxOutputStream (org.apache.geode.pdx.internal.PdxOutputStream)2