From a02ee5ec9950c099961cd35c2b3381eca0d30db2 Mon Sep 17 00:00:00 2001 From: John Blum Date: Tue, 18 Sep 2018 20:51:29 -0700 Subject: [PATCH] Add mock object support for mocking Apache Geode/Pivotal GemFire DiskStore objects. --- .../tests/mock/DiskStoreMockObjects.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/mock/DiskStoreMockObjects.java diff --git a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/mock/DiskStoreMockObjects.java b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/mock/DiskStoreMockObjects.java new file mode 100644 index 0000000..f787273 --- /dev/null +++ b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/mock/DiskStoreMockObjects.java @@ -0,0 +1,62 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.springframework.data.gemfire.tests.mock; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.util.UUID; + +import org.apache.geode.cache.DiskStore; + +/** + * The {@link DiskStoreMockObjects} class is a mock objects class allowing users to manually mock Apache Geode + * or Pivotal GemFire {@link DiskStore} objects and related objects in the {@literal org.apache.geode.cache} package. + * + * @author John Blum + * @see org.apache.geode.cache.DiskStore + * @see org.mockito.Mockito + * @see org.springframework.data.gemfire.tests.mock.MockObjectsSupport + * @since 1.0.0 + */ +@SuppressWarnings("unused") +public abstract class DiskStoreMockObjects extends MockObjectsSupport { + + public static DiskStore mockDiskStore(String name, boolean allowForceCompaction, boolean autoCompact, + int compactionThreshold, File[] diskDirectories, int[] diskDirectorySizes, float diskUsageCriticalPercentage, + float diskUsageWarningPercentage, long maxOplogSize, int queueSize, long timeInterval, int writeBufferSize) { + + DiskStore mockDiskStore = mock(DiskStore.class, name); + + when(mockDiskStore.getAllowForceCompaction()).thenReturn(allowForceCompaction); + when(mockDiskStore.getAutoCompact()).thenReturn(autoCompact); + when(mockDiskStore.getCompactionThreshold()).thenReturn(compactionThreshold); + when(mockDiskStore.getDiskDirs()).thenReturn(diskDirectories); + when(mockDiskStore.getDiskDirSizes()).thenReturn(diskDirectorySizes); + when(mockDiskStore.getDiskStoreUUID()).thenReturn(UUID.randomUUID()); + when(mockDiskStore.getDiskUsageCriticalPercentage()).thenReturn(diskUsageCriticalPercentage); + when(mockDiskStore.getDiskUsageWarningPercentage()).thenReturn(diskUsageWarningPercentage); + when(mockDiskStore.getMaxOplogSize()).thenReturn(maxOplogSize); + when(mockDiskStore.getName()).thenReturn(name); + when(mockDiskStore.getQueueSize()).thenReturn(queueSize); + when(mockDiskStore.getTimeInterval()).thenReturn(timeInterval); + when(mockDiskStore.getWriteBufferSize()).thenReturn(writeBufferSize); + + return mockDiskStore; + } +}