Skip to content

Commit

Permalink
GEODE-10323: Add small changes after review (apache#7819)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertogpz authored Jul 15, 2022
1 parent a88c8b5 commit e67e38e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static MemoryAllocatorImpl createForUnitTest(OutOfOffHeapMemoryListener o
}
}
return create(oooml, stats, slabCount, offHeapMemorySize, maxSlabSize, slabs, null,
null, () -> null);
null, () -> new DummyNonRealTimeStatsUpdater());
}

private void reuse(OutOfOffHeapMemoryListener oooml, OffHeapMemoryStats newStats,
Expand Down Expand Up @@ -240,9 +240,7 @@ private MemoryAllocatorImpl(final OutOfOffHeapMemoryListener oooml,
}

void start() {
if (nonRealTimeStatsUpdater != null) {
nonRealTimeStatsUpdater.start(updateOffHeapStatsFrequencyMs);
}
nonRealTimeStatsUpdater.start(updateOffHeapStatsFrequencyMs);
}

public List<OffHeapStoredObject> getLostChunks(InternalCache cache) {
Expand Down Expand Up @@ -540,4 +538,16 @@ public synchronized List<MemoryBlock> getOrphans(InternalCache cache) {
public MemoryInspector getMemoryInspector() {
return memoryInspector;
}

public static class DummyNonRealTimeStatsUpdater extends NonRealTimeStatsUpdater {
public DummyNonRealTimeStatsUpdater() {
super(null);
}

@Override
void start(int frequency) {}

@Override
void stop() {};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.internal.offheap;

import static org.apache.geode.internal.offheap.MemoryAllocatorImpl.DummyNonRealTimeStatsUpdater;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void testCreate() {
try {
MemoryAllocatorImpl.create(listener, stats, 10, 950, 100, null, size -> {
throw new OutOfMemoryError("expected");
}, null, () -> null);
}, null, () -> new DummyNonRealTimeStatsUpdater());
} catch (OutOfMemoryError expected) {
}
assertTrue(listener.isClosed());
Expand All @@ -99,7 +100,7 @@ public Slab create(int size) {
}
};
MemoryAllocatorImpl.create(listener, stats, 10, 950, MAX_SLAB_SIZE, null, factory, null,
() -> null);
() -> new MemoryAllocatorImpl.DummyNonRealTimeStatsUpdater());
} catch (OutOfMemoryError expected) {
}
assertTrue(listener.isClosed());
Expand All @@ -111,7 +112,7 @@ public Slab create(int size) {
SlabFactory factory = SlabImpl::new;
MemoryAllocator ma =
MemoryAllocatorImpl.create(listener, stats, 10, 950, 100, null, factory, null,
() -> null);
() -> new DummyNonRealTimeStatsUpdater());
try {
assertFalse(listener.isClosed());
assertFalse(stats.isClosed());
Expand All @@ -138,7 +139,7 @@ public Slab create(int size) {
stats2 = new NullOffHeapMemoryStats();
MemoryAllocator ma2 =
MemoryAllocatorImpl.create(listener, stats2, 10, 950, 100, null, factory, null,
() -> null);
() -> new DummyNonRealTimeStatsUpdater());
assertSame(ma, ma2);
assertTrue(stats.isClosed());
assertFalse(listener.isClosed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.internal.offheap;

import static org.apache.geode.internal.offheap.MemoryAllocatorImpl.DummyNonRealTimeStatsUpdater;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void setUp() {
OffHeapMemoryStats stats = mock(OffHeapMemoryStats.class);

ma = MemoryAllocatorImpl.create(ooohml, stats, 3, OffHeapStorage.MIN_SLAB_SIZE * 3,
OffHeapStorage.MIN_SLAB_SIZE, null, () -> null);
OffHeapStorage.MIN_SLAB_SIZE, null, () -> new DummyNonRealTimeStatsUpdater());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.geode.internal.cache.entries.DiskEntry;
import org.apache.geode.internal.cache.entries.OffHeapRegionEntry;
import org.apache.geode.internal.cache.entries.VersionedStatsDiskRegionEntryOffHeap;
import org.apache.geode.internal.offheap.MemoryAllocatorImpl.DummyNonRealTimeStatsUpdater;
import org.apache.geode.internal.serialization.DSCODE;

public class OffHeapRegionEntryHelperInstanceTest {
Expand All @@ -81,7 +82,7 @@ public void setUp() {

memoryAllocator =
MemoryAllocatorImpl.create(listener, stats, 1, OffHeapStorage.MIN_SLAB_SIZE,
OffHeapStorage.MIN_SLAB_SIZE, null, () -> null);
OffHeapStorage.MIN_SLAB_SIZE, null, () -> new DummyNonRealTimeStatsUpdater());

offHeapRegionEntryHelperInstance =
spy(new OffHeapRegionEntryHelperInstance(ohAddress -> offHeapStoredObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.geode.distributed.internal.DistributionStats;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.internal.offheap.MemoryAllocatorImpl.DummyNonRealTimeStatsUpdater;
import org.apache.geode.internal.statistics.LocalStatisticsFactory;
import org.apache.geode.util.internal.GeodeGlossary;

Expand Down Expand Up @@ -168,7 +169,7 @@ public void testCreateOffHeapStorage() {
OutOfOffHeapMemoryListener ooohml = mock(OutOfOffHeapMemoryListener.class);
MemoryAllocator ma =
OffHeapStorage.basicCreateOffHeapStorage(localStatsFactory, 1024 * 1024, ooohml, null,
() -> null);
() -> new DummyNonRealTimeStatsUpdater());
try {
OffHeapMemoryStats stats = ma.getStats();
assertNotNull(stats.getStats());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.geode.internal.cache.CachePerfStats;
import org.apache.geode.internal.cache.EntryEventImpl;
import org.apache.geode.internal.cache.RegionEntryContext;
import org.apache.geode.internal.offheap.MemoryAllocatorImpl.DummyNonRealTimeStatsUpdater;
import org.apache.geode.internal.offheap.MemoryBlock.State;
import org.apache.geode.internal.serialization.DSCODE;
import org.apache.geode.internal.serialization.KnownVersion;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void setUp() {
OffHeapMemoryStats stats = mock(OffHeapMemoryStats.class);

ma = MemoryAllocatorImpl.create(ooohml, stats, 3, OffHeapStorage.MIN_SLAB_SIZE * 3,
OffHeapStorage.MIN_SLAB_SIZE, null, () -> null);
OffHeapStorage.MIN_SLAB_SIZE, null, () -> new DummyNonRealTimeStatsUpdater());
}

@After
Expand Down

0 comments on commit e67e38e

Please sign in to comment.