Skip to content

Commit

Permalink
GEODE-6871: Disk free space info exposed via JMX (apache#4067)
Browse files Browse the repository at this point in the history
* GEODE-6871: Disk free space info exposed via JMX

- fix test cases naming
- defaults for getDiskUsagePercentage & getDiskFreePercentage
- Change test case name
  • Loading branch information
alb3rtobr authored and mhansonp committed Oct 11, 2019
1 parent 91cc1b6 commit 7440b89
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ public void queueSizeStatIncrementedAfterAsyncFlush() throws Exception {
}

@Test
public void givenDiskStoreIsCreatedWithMaxSize_thenGetDiskUsagePercentageShouldBeZero()
public void givenDiskStoreIsCreatedWithMaxSizeThenDiskUsagePercentagesShouldBeZeroAndDiskFreePercentagesShouldBe100()
throws Exception {

final int ALLOWED_MARGIN = 1;
File[] diskDirs = new File[2];
diskDirs[0] = temporaryDirectory.newFolder("dir1");
diskDirs[1] = temporaryDirectory.newFolder("dir2");
Expand All @@ -121,13 +122,16 @@ public void givenDiskStoreIsCreatedWithMaxSize_thenGetDiskUsagePercentageShouldB
DiskStore diskStore = cache.findDiskStore(DISK_STORE_NAME);

assertEquals(0, ((DiskStoreImpl) diskStore).getDiskUsagePercentage(), 0);
assertEquals(100, ((DiskStoreImpl) diskStore).getDiskFreePercentage(),
ALLOWED_MARGIN);
}

@Test
public void givenDiskStoreIsCreatedWithMaxSize_whenDataIsStored_thenGetDiskUsagePercentageShouldBeIncreased()
public void givenDiskStoreIsCreatedWithMaxSizeWhenDataIsStoredThenDiskPercentagesShouldBeModified()
throws Exception {

final int ESTIMATED_USAGE_PERCENTAGE = 7; // Estimated disk percentage for NUM_ENTRIES
final int ESTIMATED_FREE_PERCENTAGE = 100 - ESTIMATED_USAGE_PERCENTAGE;
final int ALLOWED_MARGIN = 2;

File[] diskDirs = new File[2];
Expand All @@ -150,10 +154,12 @@ public void givenDiskStoreIsCreatedWithMaxSize_whenDataIsStored_thenGetDiskUsage

assertEquals(ESTIMATED_USAGE_PERCENTAGE, ((DiskStoreImpl) diskStore).getDiskUsagePercentage(),
ALLOWED_MARGIN);
assertEquals(ESTIMATED_FREE_PERCENTAGE, ((DiskStoreImpl) diskStore).getDiskFreePercentage(),
ALLOWED_MARGIN);
}

@Test
public void givenDiskStoreIsCreatedWithDefaultSize_thenGetDiskUsagePercentageShouldNotBeAvailable()
public void givenDiskStoreIsCreatedWithDefaultSizeThenDiskPercentagesShouldNotBeAvailable()
throws Exception {

File[] diskDirs = new File[2];
Expand All @@ -166,10 +172,12 @@ public void givenDiskStoreIsCreatedWithDefaultSize_thenGetDiskUsagePercentageSho

assertEquals(ManagementConstants.NOT_AVAILABLE_FLOAT,
((DiskStoreImpl) diskStore).getDiskUsagePercentage(), 0);
assertEquals(ManagementConstants.NOT_AVAILABLE_FLOAT,
((DiskStoreImpl) diskStore).getDiskFreePercentage(), 0);
}

@Test
public void givenDiskStoreIsCreatedWithDefaultSize_whenDataIsStored_thenGetDiskUsagePercentageShouldNotBeAvailable()
public void givenDiskStoreIsCreatedWithDefaultSizeWhenDataIsStoredThenDiskPercentagesShouldNotBeAvailable()
throws Exception {

File[] diskDirs = new File[2];
Expand All @@ -186,10 +194,12 @@ public void givenDiskStoreIsCreatedWithDefaultSize_whenDataIsStored_thenGetDiskU

assertEquals(ManagementConstants.NOT_AVAILABLE_FLOAT,
((DiskStoreImpl) diskStore).getDiskUsagePercentage(), 0);
assertEquals(ManagementConstants.NOT_AVAILABLE_FLOAT,
((DiskStoreImpl) diskStore).getDiskFreePercentage(), 0);
}

@Test
public void givenDiskStoreIsCreatedWithAtLeastOneDefaultSize_thenGetDiskUsagePercentageShouldNotBeAvailable()
public void givenDiskStoreIsCreatedWithAtLeastOneDefaultSizeThenDiskPercentagesShouldNotBeAvailable()
throws Exception {

File[] diskDirs = new File[3];
Expand All @@ -210,12 +220,14 @@ public void givenDiskStoreIsCreatedWithAtLeastOneDefaultSize_thenGetDiskUsagePer

assertEquals(ManagementConstants.NOT_AVAILABLE_FLOAT,
((DiskStoreImpl) diskStore).getDiskUsagePercentage(), 0);
assertEquals(ManagementConstants.NOT_AVAILABLE_FLOAT,
((DiskStoreImpl) diskStore).getDiskFreePercentage(), 0);
cache.close();
}
}

@Test
public void givenDiskStoreIsCreatedWithAtLeastOneDefaultSize_whenDataIsStored_thenGetDiskUsagePercentageShouldNotBeAvailable()
public void givenDiskStoreIsCreatedWithAtLeastOneDefaultSizeWhenDataIsStoredThenDiskPercentagesShouldNotBeAvailable()
throws Exception {

File[] diskDirs = new File[2];
Expand All @@ -236,10 +248,12 @@ public void givenDiskStoreIsCreatedWithAtLeastOneDefaultSize_whenDataIsStored_th

assertEquals(ManagementConstants.NOT_AVAILABLE_FLOAT,
((DiskStoreImpl) diskStore).getDiskUsagePercentage(), 0);
assertEquals(ManagementConstants.NOT_AVAILABLE_FLOAT,
((DiskStoreImpl) diskStore).getDiskFreePercentage(), 0);
}

@Test
public void whenMaxOplogFileDoesNotFitInDir_thenNextDirIsSelected() throws Exception {
public void whenMaxOplogFileDoesNotFitInDirThenNextDirIsSelected() throws Exception {

File[] diskDirs = new File[3];
diskDirs[0] = temporaryDirectory.newFolder("dir1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4666,4 +4666,14 @@ public float getDiskUsagePercentage() {
return usage;
}

/**
* Returns the free space percentage of the disk store, or -1 in case
* one or more directories have unlimited storage.
*/
public float getDiskFreePercentage() {
if (this.totalDiskStoreSpace == ManagementConstants.NOT_AVAILABLE_LONG) {
return ManagementConstants.NOT_AVAILABLE_FLOAT;
}
return (100 - getDiskUsagePercentage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.apache.geode.management;

import org.apache.geode.cache.DiskStore;
import org.apache.geode.management.internal.ManagementConstants;
import org.apache.geode.management.internal.security.ResourceOperation;
import org.apache.geode.security.ResourcePermission.Operation;
import org.apache.geode.security.ResourcePermission.Resource;
Expand Down Expand Up @@ -192,9 +193,22 @@ public interface DiskStoreMXBean {
float getDiskUsageCriticalPercentage();

/**
* Returns the usage percentage of the disk storage
* Returns the usage percentage of this disk storage if directories where created with max size.
*
* @since Geode 1.10
*/
default float getDiskUsagePercentage() {
return ManagementConstants.NOT_AVAILABLE_FLOAT;
}

/**
* Returns the free percentage of this disk storage if directories where created with max size.
*
* * @since Geode 1.11
*/
float getDiskUsagePercentage();
default float getDiskFreePercentage() {
return ManagementConstants.NOT_AVAILABLE_FLOAT;
}

/**
* Sets the value of the disk usage warning percentage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public float getDiskUsagePercentage() {
return bridge.getDiskUsagePercentage();
}

@Override
public float getDiskFreePercentage() {
return bridge.getDiskFreePercentage();
}

public DiskStoreMBeanBridge getBridge() {
return bridge;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,8 @@ public void setDiskUsageCriticalPercentage(float criticalPercent) {
public float getDiskUsagePercentage() {
return diskStore.getDiskUsagePercentage();
}

public float getDiskFreePercentage() {
return diskStore.getDiskFreePercentage();
}
}

0 comments on commit 7440b89

Please sign in to comment.