@Test
  public void testByteSize() throws Exception {
    vm0.invoke(() -> createPartitionedRegion(200));
    vm1.invoke(() -> createPartitionedRegion(200));

    long bucketSizeWithOneEntry = vm0.invoke(() -> {
      Region<Integer, byte[]> region = getRegion(REGION_NAME);
      region.put(0, new byte[100]);

      PartitionedRegion partitionedRegion = (PartitionedRegion) region;
      PartitionedRegionDataStore dataStore = partitionedRegion.getDataStore();
      long size = dataStore.getBucketSize(0);

      for (int i = 1; i < 100; i++) {
        region.put(i * TOTAL_NUMBER_OF_BUCKETS, new byte[100]);
      }
      await().until(() -> dataStore.getBucketsManaged() == (short) 1);

      // make sure the size is proportional to the amount of data
      await().until(() -> dataStore.getBucketSize(0) == 100 * size);

      // destroy and invalidate entries and make sure the size goes down
      for (int i = 0; i < 25; i++) {
        region.destroy(i * TOTAL_NUMBER_OF_BUCKETS);
      }

      for (int i = 25; i < 50; i++) {
        region.invalidate(i * TOTAL_NUMBER_OF_BUCKETS);
      }

      await().until(() -> dataStore.getBucketSize(0) == 50 * size);

      // put some larger values in and make sure the size goes up
      for (int i = 50; i < 75; i++) {
        region.put(i * TOTAL_NUMBER_OF_BUCKETS, new byte[150]);
      }

      // Now put in some smaller values and see if the size balances out
      for (int i = 75; i < 100; i++) {
        region.put(i * TOTAL_NUMBER_OF_BUCKETS, new byte[50]);
      }

      await().until(() -> dataStore.getBucketSize(0) == 50 * size);

      return size;
    });

    vm1.invoke(() -> {
      PartitionedRegion partitionedRegion = getPartitionedRegion(REGION_NAME);
      await().until(
          () -> partitionedRegion.getDataStore().getBucketSize(0) == 50 * bucketSizeWithOneEntry);
    });

    vm1.invoke(() -> {
      PartitionedRegion partitionedRegion = getPartitionedRegion(REGION_NAME);
      PartitionedRegionDataStore dataStore = partitionedRegion.getDataStore();
      await().until(() -> dataStore.currentAllocatedMemory() == 50 * bucketSizeWithOneEntry);
    });
  }
Regression test for TRAC #39868

<p>
TRAC #39868: PartitionMemberDetails.getSize() reports negative PR sizes when redundancy is 0
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PartitionedRegionSizeDUnitTest.java