You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2018/04/28 00:00:28 UTC
[geode] 06/06: GEODE-5096: Commit with Lucene testcases failing...
Just to kickoff regression
This is an automated email from the ASF dual-hosted git repository.
udo pushed a commit to branch feature/GEODE-5096
in repository https://gitbox.apache.org/repos/asf/geode.git
commit 38ceffa3b083a3b522b9163718289fccd340acd1
Author: Udo Kohlmeyer <uk...@pivotal.io>
AuthorDate: Fri Apr 27 16:59:20 2018 -0700
GEODE-5096: Commit with Lucene testcases failing... Just to kickoff regression
---
.../distributed/internal/DistributionAdvisor.java | 12 +-
.../org/apache/geode/internal/DSFIDFactory.java | 20 +-
.../geode/internal/DataSerializableFixedID.java | 3 +
.../geode/internal/cache/InternalRegion.java | 8 +-
.../apache/geode/internal/cache/LocalRegion.java | 79 +++--
.../geode/internal/cache/PartitionedRegion.java | 172 +++++-----
.../internal/cache/UpdateAttributesProcessor.java | 85 ++---
.../cache/ValidateCacheServerProfileProcessor.java | 357 +++++++++++++++++++++
.../geode/test/dunit/standalone/DUnitLauncher.java | 17 +-
.../internal/LuceneIndexCreationProfile.java | 1 +
.../cache/lucene/internal/LuceneServiceImpl.java | 17 +-
.../geode/cache/lucene/EvictionDUnitTest.java | 35 +-
.../geode/cache/lucene/ExpirationDUnitTest.java | 4 +-
.../lucene/LuceneClientSecurityDUnitTest.java | 27 +-
.../apache/geode/cache/lucene/LuceneDUnitTest.java | 71 ++--
.../cache/lucene/LuceneIndexCreationDUnitTest.java | 132 ++++----
.../cache/lucene/LuceneIndexDestroyDUnitTest.java | 116 +++----
.../cache/lucene/LuceneQueriesAccessorBase.java | 82 +++--
.../cache/lucene/LuceneQueriesClientDUnitTest.java | 26 +-
.../geode/cache/lucene/LuceneQueriesDUnitTest.java | 67 ++--
.../LuceneQueriesReindexClientDUnitTest.java | 12 +-
.../lucene/LuceneQueriesReindexDUnitTest.java | 78 +++--
.../cache/lucene/MixedObjectIndexDUnitTest.java | 34 +-
.../geode/cache/lucene/PaginationDUnitTest.java | 48 ++-
.../geode/cache/lucene/RebalanceDUnitTest.java | 23 +-
.../lucene/RebalanceWithRedundancyDUnitTest.java | 38 +--
...ncyWithRegionCreatedBeforeReindexDUnitTest.java | 131 +++-----
27 files changed, 1096 insertions(+), 599 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionAdvisor.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionAdvisor.java
index a3be6cf..c8555c5 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionAdvisor.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionAdvisor.java
@@ -1176,8 +1176,9 @@ public class DistributionAdvisor {
DistributionAdvisee advisee = getAdvisee();
do {
advisee = advisee.getParentAdvisee();
- if (advisee == null)
+ if (advisee == null) {
return getDefaultDistributionMembers();
+ }
advisor = advisee.getDistributionAdvisor();
} while (!advisor.isInitialized());
// do not call adviseGeneric because we don't want to trigger another
@@ -1276,7 +1277,7 @@ public class DistributionAdvisor {
protected void profileRemoved(Profile profile) {}
/** All advise methods go through this method */
- protected Set<InternalDistributedMember> adviseFilter(Filter f) {
+ protected Set<InternalDistributedMember> adviseFilter(Filter filter) {
initializationGate();
if (disabled) {
if (logger.isDebugEnabled()) {
@@ -1286,11 +1287,10 @@ public class DistributionAdvisor {
}
Set<InternalDistributedMember> recipients = null;
Profile[] locProfiles = this.profiles; // grab current profiles
- for (int i = 0; i < locProfiles.length; i++) {
- Profile profile = locProfiles[i];
- if (f == null || f.include(profile)) {
+ for (Profile profile : locProfiles) {
+ if (filter == null || filter.include(profile)) {
if (recipients == null) {
- recipients = new HashSet<InternalDistributedMember>();
+ recipients = new HashSet<>();
}
recipients.add(profile.getDistributedMember());
}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/DSFIDFactory.java b/geode-core/src/main/java/org/apache/geode/internal/DSFIDFactory.java
index 204459f..de534bd 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/DSFIDFactory.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/DSFIDFactory.java
@@ -265,6 +265,7 @@ import org.apache.geode.internal.cache.UpdateAttributesProcessor;
import org.apache.geode.internal.cache.UpdateEntryVersionOperation.UpdateEntryVersionMessage;
import org.apache.geode.internal.cache.UpdateOperation;
import org.apache.geode.internal.cache.VMCachedDeserializable;
+import org.apache.geode.internal.cache.ValidateCacheServerProfileProcessor;
import org.apache.geode.internal.cache.backup.AbortBackupRequest;
import org.apache.geode.internal.cache.backup.BackupResponse;
import org.apache.geode.internal.cache.backup.FinishBackupRequest;
@@ -451,7 +452,9 @@ public class DSFIDFactory implements DataSerializableFixedID {
registerDSFIDTypes();
}
- /** Register the constructor for a fixed ID class. */
+ /**
+ * Register the constructor for a fixed ID class.
+ */
public static void registerDSFID(int dsfid, Class dsfidClass) {
try {
Constructor<?> cons = dsfidClass.getConstructor((Class[]) null);
@@ -874,12 +877,12 @@ public class DSFIDFactory implements DataSerializableFixedID {
registerDSFID(END_BUCKET_CREATION_MESSAGE, EndBucketCreationMessage.class);
registerDSFID(PREPARE_BACKUP_REQUEST, PrepareBackupRequest.class);
registerDSFID(BACKUP_RESPONSE, BackupResponse.class); // in older versions this was
- // FinishBackupResponse which is
- // compatible
+ // FinishBackupResponse which is
+ // compatible
registerDSFID(FINISH_BACKUP_REQUEST, FinishBackupRequest.class);
registerDSFID(FINISH_BACKUP_RESPONSE, BackupResponse.class); // for backwards compatibility map
- // FINISH_BACKUP_RESPONSE to
- // BackupResponse
+ // FINISH_BACKUP_RESPONSE to
+ // BackupResponse
registerDSFID(COMPACT_REQUEST, CompactRequest.class);
registerDSFID(COMPACT_RESPONSE, CompactResponse.class);
registerDSFID(FLOW_CONTROL_PERMIT_MESSAGE, FlowControlPermitMessage.class);
@@ -937,6 +940,11 @@ public class DSFIDFactory implements DataSerializableFixedID {
registerDSFID(GATEWAY_SENDER_QUEUE_ENTRY_SYNCHRONIZATION_ENTRY,
GatewaySenderQueueEntrySynchronizationOperation.GatewaySenderQueueEntrySynchronizationEntry.class);
registerDSFID(ABORT_BACKUP_REQUEST, AbortBackupRequest.class);
+
+ registerDSFID(VALIDATE_CACHE_PROFILE_MESSAGE,
+ ValidateCacheServerProfileProcessor.ValidateCacheProfileMessage.class);
+ registerDSFID(VALIDATE_CACHE_SERVER_REPLY_MESSAGE,
+ ValidateCacheServerProfileProcessor.ValidateCacheServerProfileReplyMessage.class);
}
/**
@@ -1009,8 +1017,8 @@ public class DSFIDFactory implements DataSerializableFixedID {
}
}
-
////////////////// Reading Internal Objects /////////////////
+
/**
* Reads an instance of <code>IpAddress</code> from a <code>DataInput</code>.
*
diff --git a/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java b/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
index b5b6b5e..4cfffd3 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
@@ -823,6 +823,9 @@ public interface DataSerializableFixedID extends SerializationVersions {
short GATEWAY_SENDER_QUEUE_ENTRY_SYNCHRONIZATION_ENTRY = 2182;
short ABORT_BACKUP_REQUEST = 2183;
+ short VALIDATE_CACHE_PROFILE_MESSAGE = 2184;
+ short VALIDATE_CACHE_SERVER_REPLY_MESSAGE = 2185;
+
// NOTE, codes > 65535 will take 4 bytes to serialize
/**
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/InternalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/InternalRegion.java
index 2959376..d7d251e 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/InternalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/InternalRegion.java
@@ -142,9 +142,6 @@ public interface InternalRegion extends Region, HasCachePerfStats, RegionEntryCo
InternalRegionArguments internalRegionArgs)
throws RegionExistsException, TimeoutException, IOException, ClassNotFoundException;
- void addCacheServiceProfile(CacheServiceProfile profile)
- throws IncompatibleCacheServiceProfileException;
-
void setEvictionMaximum(int maximum);
/**
@@ -241,4 +238,9 @@ public interface InternalRegion extends Region, HasCachePerfStats, RegionEntryCo
boolean generateEventID();
boolean containsTombstone(Object key);
+
+ void addCacheServiceProfile(CacheServiceProfile profile)
+ throws IncompatibleCacheServiceProfileException;
+
+ void removeCacheServiceProfile(CacheServiceProfile profile);
}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index bb7a03a..b05a6dd 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -299,13 +299,19 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
*/
private volatile boolean reinitialized_new = false;
- /** Lock used to prevent multiple concurrent destroy region operations */
+ /**
+ * Lock used to prevent multiple concurrent destroy region operations
+ */
private Semaphore destroyLock;
- /** GuardedBy regionExpiryLock. */
+ /**
+ * GuardedBy regionExpiryLock.
+ */
private RegionTTLExpiryTask regionTTLExpiryTask = null;
- /** GuardedBy regionExpiryLock. */
+ /**
+ * GuardedBy regionExpiryLock.
+ */
private RegionIdleExpiryTask regionIdleExpiryTask = null;
private final Object regionExpiryLock = new Object();
@@ -390,7 +396,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
*/
private volatile boolean initialized = false; // added for bug 30223
- /** Used for accessing region data on disk */
+ /**
+ * Used for accessing region data on disk
+ */
private final DiskRegion diskRegion;
/**
@@ -696,13 +704,17 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
return eventTracker;
}
- /** returns the regions version-vector */
+ /**
+ * returns the regions version-vector
+ */
@Override
public RegionVersionVector getVersionVector() {
return this.versionVector;
}
- /** returns object used to guard the size() operation during tombstone removal */
+ /**
+ * returns object used to guard the size() operation during tombstone removal
+ */
Object getSizeGuard() {
if (!this.getConcurrencyChecksEnabled()) {
return new Object();
@@ -719,7 +731,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
return null;
}
- /** initializes a new version vector for this region */
+ /**
+ * initializes a new version vector for this region
+ */
private RegionVersionVector createVersionVector() {
RegionVersionVector regionVersionVector = RegionVersionVector.create(getVersionMember(), this);
@@ -805,7 +819,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
return this.serverRegionProxy != null;
}
- /** Returns true if the ExpiryTask is currently allowed to expire. */
+ /**
+ * Returns true if the ExpiryTask is currently allowed to expire.
+ */
protected boolean isExpirationAllowed(ExpiryTask expiry) {
return true;
}
@@ -1741,7 +1757,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
return getDataView().getEntry(getKeyInfo(key), this, false);
}
- /** internally we often need to get an entry whether it is a tombstone or not */
+ /**
+ * internally we often need to get an entry whether it is a tombstone or not
+ */
public Region.Entry getEntry(Object key, boolean allowTombstones) {
return getDataView().getEntry(getKeyInfo(key), this, allowTombstones);
}
@@ -1763,7 +1781,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
}
}
- /** a fast estimate of total number of entries locally in the region */
+ /**
+ * a fast estimate of total number of entries locally in the region
+ */
public long getEstimatedLocalSize() {
if (!this.isDestroyed) {
long size;
@@ -1821,7 +1841,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
return this.isDestroyed;
}
- /** returns true if this region has been destroyed */
+ /**
+ * returns true if this region has been destroyed
+ */
@Override
public boolean isDestroyed() {
if (isClosed()) {
@@ -1843,7 +1865,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
return false;
}
- /** a variant of subregions() that does not perform a readiness check */
+ /**
+ * a variant of subregions() that does not perform a readiness check
+ */
@Override
public Set basicSubregions(boolean recursive) {
return new SubregionsSet(recursive);
@@ -1865,7 +1889,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
return basicEntries(recursive);
}
- /** Returns set of entries without performing validation checks. */
+ /**
+ * Returns set of entries without performing validation checks.
+ */
public Set basicEntries(boolean recursive) {
return new EntriesSet(this, recursive, IteratorType.ENTRIES, false);
}
@@ -2061,7 +2087,6 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
* Returns the {@code DiskRegion} that this region uses to access data on disk.
*
* @return {@code null} if disk regions are not being used
- *
* @since GemFire 3.2
*/
@Override
@@ -2730,7 +2755,6 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
}
/**
- *
* Search for the value in a server (if one exists), then try a loader.
*
* If we find a value, we put it in the cache.
@@ -2927,7 +2951,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
return result;
}
- /** @return true if this was a client region; false if not */
+ /**
+ * @return true if this was a client region; false if not
+ */
@Override
public boolean bridgeWriteBeforeDestroy(EntryEventImpl event, Object expectedOldValue)
throws CacheWriterException, EntryNotFoundException, TimeoutException {
@@ -4643,7 +4669,6 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
/**
* Called by a thread that is doing region initialization. Causes the initialization Latch to be
* bypassed by this thread.
- *
*/
public static int setThreadInitLevelRequirement(int level) {
int oldLevel = threadInitLevelRequirement();
@@ -10449,15 +10474,27 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
public void addCacheServiceProfile(CacheServiceProfile profile)
throws IncompatibleCacheServiceProfileException {
synchronized (this.cacheServiceProfiles) {
- this.cacheServiceProfiles.putIfAbsent(profile.getId(), profile);
- this.validateProfiles();
+ CacheServiceProfile cacheServiceProfile =
+ this.cacheServiceProfiles.putIfAbsent(profile.getId(), profile);
+ if (cacheServiceProfile == null) {
+ this.validateProfiles();
+ } else {
+ throw new IncompatibleCacheServiceProfileException(
+ "A profile for: " + profile.getId() + " has already been defined");
+ }
+
}
}
- protected boolean validateProfiles() throws IncompatibleCacheServiceProfileException {
- return true;
+ @Override
+ public void removeCacheServiceProfile(CacheServiceProfile profile) {
+ synchronized (this.cacheServiceProfiles) {
+ this.cacheServiceProfiles.remove(profile.getId(), profile);
+ }
}
+ protected void validateProfiles() throws IncompatibleCacheServiceProfileException {}
+
@Override
public LoaderHelper createLoaderHelper(Object key, Object callbackArgument,
boolean netSearchAllowed, boolean netLoadAllowed, SearchLoadAndWriteProcessor searcher) {
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
index 13a5752..bab9df5 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
@@ -299,16 +299,13 @@ public class PartitionedRegion extends LocalRegion
/**
* Thread specific random number
*/
- private static ThreadLocal threadRandom = new ThreadLocal() {
- @Override
- protected Object initialValue() {
- int i = RANDOM.nextInt();
- if (i < 0) {
- i = -1 * i;
- }
- return i;
+ private static ThreadLocal threadRandom = ThreadLocal.withInitial(() -> {
+ int i = RANDOM.nextInt();
+ if (i < 0) {
+ i = -1 * i;
}
- };
+ return i;
+ });
/**
* Global Region for storing PR config ( PRName->PRConfig). This region would be used to resolve
@@ -317,7 +314,6 @@ public class PartitionedRegion extends LocalRegion
private volatile Region<String, PartitionRegionConfig> prRoot;
/**
- *
* PartitionedRegionDataStore class takes care of data storage for the PR. This will contain the
* bucket Regions to store data entries for PR*
*/
@@ -328,13 +324,19 @@ public class PartitionedRegion extends LocalRegion
*/
private final RegionAdvisor distAdvisor;
- /** Logging mechanism for debugging */
+ /**
+ * Logging mechanism for debugging
+ */
private static final Logger logger = LogService.getLogger();
- /** cleanup flags * */
+ /**
+ * cleanup flags *
+ */
private boolean cleanPRRegistration = false;
- /** Time to wait for for acquiring distributed lock ownership */
+ /**
+ * Time to wait for for acquiring distributed lock ownership
+ */
private static final long VM_OWNERSHIP_WAIT_TIME = PRSystemPropertyGetter.parseLong(
System.getProperty(PartitionedRegionHelper.VM_OWNERSHIP_WAIT_TIME_PROPERTY),
PartitionedRegionHelper.VM_OWNERSHIP_WAIT_TIME_DEFAULT);
@@ -359,10 +361,14 @@ public class PartitionedRegion extends LocalRegion
*/
static final float rebalanceThreshold = 0.75f;
- /** The maximum memory allocated for this node in Mb */
+ /**
+ * The maximum memory allocated for this node in Mb
+ */
final int localMaxMemory;
- /** The maximum milliseconds for retrying operations */
+ /**
+ * The maximum milliseconds for retrying operations
+ */
private final int retryTimeout;
/**
@@ -372,7 +378,9 @@ public class PartitionedRegion extends LocalRegion
// private Random random = new Random(System.currentTimeMillis());
- /** Number of initial buckets */
+ /**
+ * Number of initial buckets
+ */
private final int totalNumberOfBuckets;
// private static final boolean throwIfNoNodesLeft = true;
@@ -396,7 +404,6 @@ public class PartitionedRegion extends LocalRegion
/**
* Flag to indicate whether region is closed
- *
*/
public volatile boolean isClosed = false;
@@ -477,14 +484,8 @@ public class PartitionedRegion extends LocalRegion
}
@Override
- protected boolean validateProfiles() throws IncompatibleCacheServiceProfileException {
- try {
- new CreateRegionProcessor((PartitionedRegion) this).initializeRegion();
- return true;
- } catch (Exception e) {
- throw new IncompatibleCacheServiceProfileException(e.getMessage());
- }
- // new UpdateAttributesProcessor((PartitionedRegion) this).validateProfiles()
+ protected void validateProfiles() throws IncompatibleCacheServiceProfileException {
+ new ValidateCacheServerProfileProcessor(this).validateCacheServerProfiles();
}
static PRIdMap getPrIdToPR() {
@@ -572,7 +573,9 @@ public class PartitionedRegion extends LocalRegion
return getPRId() + BUCKET_ID_SEPARATOR + bucketId;
}
- /** Separator between PRId and bucketId for creating bucketString */
+ /**
+ * Separator between PRId and bucketId for creating bucketString
+ */
public static final String BUCKET_ID_SEPARATOR = ":";
/**
@@ -670,8 +673,9 @@ public class PartitionedRegion extends LocalRegion
.toLocalizedString());
}
Assert.assertTrue(key instanceof Integer);
- if (sendIdentityRequestMessage)
+ if (sendIdentityRequestMessage) {
IdentityRequestMessage.setLatestId((Integer) key);
+ }
if ((super.get(key) == DESTROYED) && (value instanceof PartitionedRegion)) {
throw new PartitionedRegionException(
LocalizedStrings.PartitionedRegion_CAN_NOT_REUSE_OLD_PARTITIONED_REGION_ID_0
@@ -703,10 +707,14 @@ public class PartitionedRegion extends LocalRegion
private int partitionedRegionId = -3;
- /** Node description */
+ /**
+ * Node description
+ */
private final Node node;
- /** Helper Object for redundancy Management of PartitionedRegion */
+ /**
+ * Helper Object for redundancy Management of PartitionedRegion
+ */
private final PRHARedundancyProvider redundancyProvider;
/**
@@ -1343,7 +1351,6 @@ public class PartitionedRegion extends LocalRegion
*
* @param storesData which indicates whether the instance in this cache stores data, effecting the
* Nodes PRType
- *
* @see Node#setPRType(int)
*/
private void registerPartitionedRegion(boolean storesData) {
@@ -1764,9 +1771,9 @@ public class PartitionedRegion extends LocalRegion
* @param key the key, whose value needs to be checks
* @param access true if caller wants last access time updated
* @param allowTombstones whether tombstones should be returned
+ * @return true if the passed key is contained remotely.
* @throws EntryNotFoundException if the entry doesn't exist
* @throws ForceReattemptException if the peer is no longer available
- * @return true if the passed key is contained remotely.
*/
public EntrySnapshot getEntryRemotely(InternalDistributedMember targetNode, Integer bucketId,
Object key, boolean access, boolean allowTombstones)
@@ -1787,8 +1794,8 @@ public class PartitionedRegion extends LocalRegion
// /////////////////////////////////////////////////////////////////
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public void becomeLockGrantor() {
@@ -1796,8 +1803,8 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public Region createSubregion(String subregionName, RegionAttributes regionAttributes)
@@ -1806,8 +1813,8 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public Lock getDistributedLock(Object key) throws IllegalStateException {
@@ -1815,8 +1822,8 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public CacheStatistics getStatistics() {
@@ -1824,16 +1831,16 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
public Region getSubregion() {
throw new UnsupportedOperationException();
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public Lock getRegionDistributedLock() throws IllegalStateException {
@@ -1842,8 +1849,8 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public void loadSnapshot(InputStream inputStream)
@@ -1861,8 +1868,8 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public void localInvalidate(Object key, Object aCallbackArgument) throws EntryNotFoundException {
@@ -1871,8 +1878,8 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public void localInvalidateRegion(Object aCallbackArgument) {
@@ -1885,7 +1892,6 @@ public class PartitionedRegion extends LocalRegion
* query is a SELECT expression, and the only region it refers to is this region.
*
* @see DefaultQuery#execute()
- *
* @since GemFire 5.1
*/
public Object executeQuery(DefaultQuery query, Object[] parameters, Set buckets)
@@ -2020,8 +2026,8 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public void saveSnapshot(OutputStream outputStream) throws IOException {
@@ -2029,8 +2035,8 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public void writeToDisk() {
@@ -2038,8 +2044,8 @@ public class PartitionedRegion extends LocalRegion
}
/**
- * @since GemFire 5.0
* @throws UnsupportedOperationException OVERRIDES
+ * @since GemFire 5.0
*/
@Override
public void clear() {
@@ -2795,10 +2801,9 @@ public class PartitionedRegion extends LocalRegion
* @param ifOld true=can update existing entry false=can't update existing entry
* @param expectedOldValue only succeed if old value is equal to this value. If null, then doesn't
* matter what old value is. If INVALID token, must be INVALID.
- * @see LocalRegion#virtualPut(EntryEventImpl, boolean, boolean, Object, boolean, long, boolean)
* @return false if ifNew is true and there is an existing key, or ifOld is true and there is no
* existing entry; otherwise return true.
- *
+ * @see LocalRegion#virtualPut(EntryEventImpl, boolean, boolean, Object, boolean, long, boolean)
*/
private boolean putInBucket(final InternalDistributedMember targetNode, final Integer bucketId,
final EntryEventImpl event, final boolean ifNew, boolean ifOld, Object expectedOldValue,
@@ -3213,7 +3218,6 @@ public class PartitionedRegion extends LocalRegion
* speed up operation and avoid remote calls.
*
* @param bucketId identifier for bucket
- *
* @return the primary member's id or null if there is no storage
*/
public InternalDistributedMember getNodeForBucketRead(int bucketId) {
@@ -4713,7 +4717,7 @@ public class PartitionedRegion extends LocalRegion
nodeToBuckets.entrySet().iterator(); itr.hasNext();) {
Map.Entry<InternalDistributedMember, HashSet<Integer>> entry = itr.next();
HashSet<Integer> buckets = new HashSet<Integer>(entry.getValue()); // Is it needed to copy the
- // set here?
+ // set here?
FetchBulkEntriesResponse fber = null;
result = new HashSet();
@@ -4838,7 +4842,6 @@ public class PartitionedRegion extends LocalRegion
/**
* This method returns Partitioned Region data store associated with this Partitioned Region
- *
*/
public PartitionedRegionDataStore getDataStore() {
return this.dataStore;
@@ -4948,7 +4951,9 @@ public class PartitionedRegion extends LocalRegion
return this.distAdvisor;
}
- /** Returns the distribution profile; lazily creates one if needed */
+ /**
+ * Returns the distribution profile; lazily creates one if needed
+ */
public Profile getProfile() {
return this.distAdvisor.createProfile();
}
@@ -4990,7 +4995,9 @@ public class PartitionedRegion extends LocalRegion
profile.isOffHeap = getOffHeap();
}
- /** set fields that are only in PartitionProfile... */
+ /**
+ * set fields that are only in PartitionProfile...
+ */
public void fillInProfile(PartitionProfile profile) {
// both isDataStore and numBuckets are not required for sending purposes,
// but nice to have for toString debugging
@@ -5119,7 +5126,6 @@ public class PartitionedRegion extends LocalRegion
/**
* This method returns prId
- *
*/
public int getPRId() {
return this.partitionedRegionId;
@@ -5138,7 +5144,6 @@ public class PartitionedRegion extends LocalRegion
/**
* This method returns total number of buckets for this PR
- *
*/
public int getTotalNumberOfBuckets() {
@@ -5389,8 +5394,9 @@ public class PartitionedRegion extends LocalRegion
return true;
} else {
for (String s : groups) {
- if (localServerGroups.contains(s))
+ if (localServerGroups.contains(s)) {
return true;
+ }
}
}
}
@@ -5925,7 +5931,9 @@ public class PartitionedRegion extends LocalRegion
private class EntriesSetIterator extends KeysSetIterator {
- /** reusable KeyInfo */
+ /**
+ * reusable KeyInfo
+ */
private final KeyInfo key = new KeyInfo(null, null, null);
public EntriesSetIterator(Set bucketSet, boolean allowTombstones) {
@@ -5999,7 +6007,9 @@ public class PartitionedRegion extends LocalRegion
return Collections.unmodifiableSet(new KeysSet(availableBuckets));
}
- /** Set view of entries */
+ /**
+ * Set view of entries
+ */
protected class KeysSet extends EntriesSet {
class KeysSetIterator implements PREntriesIterator<Object> {
final Iterator<Integer> bucketSetI;
@@ -6176,7 +6186,9 @@ public class PartitionedRegion extends LocalRegion
Object nextValue = null;
- /** reusable KeyInfo */
+ /**
+ * reusable KeyInfo
+ */
private final KeyInfo key = new KeyInfo(null, null, null);
public ValuesSetIterator(Set bucketSet) {
@@ -6616,7 +6628,6 @@ public class PartitionedRegion extends LocalRegion
/**
* Returns the lockname used by Distributed Lock service to clean the
* {@code allPartitionedRegions}.
- *
*/
private String getLockNameForBucket2NodeModification(int bucketID) {
return (getRegionIdentifier() + ":" + bucketID);
@@ -6880,14 +6891,16 @@ public class PartitionedRegion extends LocalRegion
}
BucketLock other = (BucketLock) obj;
- if (!this.lockName.equals(other.lockName))
+ if (!this.lockName.equals(other.lockName)) {
return false;
+ }
DLockService ls1 = lockService;
DLockService ls2 = other.lockService;
if (ls1 == null || ls2 == null) {
- if (ls1 != ls2)
+ if (ls1 != ls2) {
return false;
+ }
}
return ls1.equals(ls2);
}
@@ -7149,7 +7162,7 @@ public class PartitionedRegion extends LocalRegion
}
if (cacheWrite) { // in case of destroy operation senders should be
- // resumed
+ // resumed
if (sender.isPaused()) {
pausedSenders.add(senderId);
continue;
@@ -7157,11 +7170,12 @@ public class PartitionedRegion extends LocalRegion
}
if (pausedSenders.isEmpty()) { // if there are puase sender then only
- // check for other pause senders instead
- // of creating list of shadowPR
+ // check for other pause senders instead
+ // of creating list of shadowPR
AbstractGatewaySenderEventProcessor ep = sender.getEventProcessor();
- if (ep == null)
+ if (ep == null) {
continue;
+ }
ConcurrentParallelGatewaySenderQueue parallelQueue =
(ConcurrentParallelGatewaySenderQueue) ep.getQueue();
PartitionedRegion parallelQueueRegion = parallelQueue.getRegion(this.getFullPath());
@@ -7206,12 +7220,12 @@ public class PartitionedRegion extends LocalRegion
if (cacheWrite && parallelQueueRegion.size() != 0 && keepWaiting) {
continue;
} else {// In any case, destroy shadow PR locally. distributed destroy of
- // userPR will take care of detsroying shadowPR locally on other
- // nodes.
+ // userPR will take care of detsroying shadowPR locally on other
+ // nodes.
RegionEventImpl event = null;
if (op.isClose()) { // In case of cache close operation, we want SPR's basic destroy to go
- // through CACHE_CLOSE condition of postDestroyRegion not
- // closePartitionedRegion code
+ // through CACHE_CLOSE condition of postDestroyRegion not
+ // closePartitionedRegion code
event = new RegionEventImpl(parallelQueueRegion, op, null, false, getMyId(),
generateEventID());
} else {
@@ -7295,7 +7309,6 @@ public class PartitionedRegion extends LocalRegion
* Destroys bucket2node region
*
* @param event the RegionEvent that triggered this operation
- *
* @see #destroyPartitionedRegionLocally(boolean)
* @see #destroyPartitionedRegionGlobally(RegionEventImpl)
* @see #destroyCleanUp(RegionEventImpl, int[])
@@ -7414,7 +7427,6 @@ public class PartitionedRegion extends LocalRegion
* Destroys bucket2node region <br>
*
* @param event the RegionEvent that triggered the region clean up
- *
* @see DestroyPartitionedRegionMessage
*/
private void destroyCleanUp(RegionEventImpl event, int serials[]) {
@@ -7509,7 +7521,6 @@ public class PartitionedRegion extends LocalRegion
* this call returns, else if process with the removal from prIdMap and dataStore cleanup.
*
* @return wether local destroy happened
- *
* @see #destroyPartitionedRegion(RegionEventImpl)
*/
boolean destroyPartitionedRegionLocally(boolean removeFromDisk) {
@@ -7969,7 +7980,9 @@ public class PartitionedRegion extends LocalRegion
return localPrimaryList;
}
- /** doesn't throw RegionDestroyedException, used by CacheDistributionAdvisor */
+ /**
+ * doesn't throw RegionDestroyedException, used by CacheDistributionAdvisor
+ */
@Override
public DistributionAdvisee getParentAdvisee() {
return (DistributionAdvisee) basicGetParentRegion();
@@ -8191,7 +8204,6 @@ public class PartitionedRegion extends LocalRegion
/**
* Returns the a PartitionedIndex on this partitioned region.
- *
*/
public PartitionedIndex getIndex(String indexName) {
Iterator iter = this.indexes.values().iterator();
@@ -8238,7 +8250,6 @@ public class PartitionedRegion extends LocalRegion
* @param indexedExpression expression for index creation.
* @param fromClause the from clause for index creation
* @param imports class to be imported for fromClause.
- *
* @return Index an index created on this region.
* @throws ForceReattemptException indicating the operation failed to create a remote index
* @throws IndexCreationException if the index is not created properly
@@ -8716,7 +8727,6 @@ public class PartitionedRegion extends LocalRegion
* Removes a particular index on this partitioned regions instance.
*
* @param ind Index to be removed.
- *
*/
public int removeIndex(Index ind, boolean remotelyOriginated)
throws CacheException, ForceReattemptException {
@@ -9222,8 +9232,8 @@ public class PartitionedRegion extends LocalRegion
* LOCAL_DESTROY and the region is {@link DataPolicy#withReplication replicated} or if the
* the ExpirationAction is LOCAL_INVALIDATE and the region is
* {@link DataPolicy#withReplication replicated}
- * @see AttributesFactory#setStatisticsEnabled
* @throws IllegalStateException if statistics are disabled for this region.
+ * @see AttributesFactory#setStatisticsEnabled
*/
@Override
public ExpirationAttributes setEntryIdleTimeout(ExpirationAttributes idleTimeout) {
@@ -9310,7 +9320,9 @@ public class PartitionedRegion extends LocalRegion
}
List<BucketRegion> bucketList = new ArrayList<>();
if (!bucketSortedOnce.get()) {
- while (bucketSortedOnce.get() == false);
+ while (bucketSortedOnce.get() == false) {
+ ;
+ }
}
bucketList.addAll(this.sortedBuckets);
return bucketList;
@@ -9740,8 +9752,9 @@ public class PartitionedRegion extends LocalRegion
* @since GemFire 6.1.2.9
*/
public BucketRegion getBucketRegion(Object key) {
- if (this.dataStore == null)
+ if (this.dataStore == null) {
return null;
+ }
Integer bucketId = PartitionedRegionHelper.getHashKey(this, null, key, null, null);
return this.dataStore.getLocalBucketById(bucketId);
}
@@ -9962,8 +9975,9 @@ public class PartitionedRegion extends LocalRegion
assert this.isShadowPR();
PartitionedRegion userPR = ColocationHelper.getLeaderRegion(this);
boolean isAccessor = (userPR.getLocalMaxMemory() == 0);
- if (isAccessor)
+ if (isAccessor) {
return; // return from here if accessor node
+ }
// Before going ahead, make sure all the buckets of shadowPR are
// loaded
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateAttributesProcessor.java b/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateAttributesProcessor.java
index 60e2527..2cfc039 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateAttributesProcessor.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateAttributesProcessor.java
@@ -54,7 +54,7 @@ public class UpdateAttributesProcessor {
private static final Logger logger = LogService.getLogger();
protected final DistributionAdvisee advisee;
- private boolean profileExchange = false;
+
/**
* If true then sender is telling receiver to remove the sender's profile. No profile exchange is
* needed in this case.
@@ -62,7 +62,6 @@ public class UpdateAttributesProcessor {
* @since GemFire 5.7
*/
private boolean removeProfile = false;
- private ReplyProcessor21 processor;
/**
* Creates a new instance of UpdateAttributesProcessor
@@ -95,11 +94,11 @@ public class UpdateAttributesProcessor {
* @param exchangeProfiles true if we want to receive profile replies
*/
public void distribute(boolean exchangeProfiles) {
- sendProfileUpdate(exchangeProfiles);
- waitForProfileResponse();
+ ReplyProcessor21 processor = sendProfileUpdate(exchangeProfiles);
+ waitForProfileResponse(processor);
}
- public void waitForProfileResponse() {
+ public void waitForProfileResponse(ReplyProcessor21 processor) {
if (processor == null) {
return;
}
@@ -117,11 +116,9 @@ public class UpdateAttributesProcessor {
}
}
-
- public void sendProfileUpdate(boolean exchangeProfiles) {
+ private ReplyProcessor21 sendProfileUpdate(boolean exchangeProfiles) {
DistributionManager mgr = this.advisee.getDistributionManager();
DistributionAdvisor advisor = this.advisee.getDistributionAdvisor();
- this.profileExchange = exchangeProfiles;
// if this is not intended for the purpose of exchanging profiles but
// the advisor is uninitialized, then just exchange profiles anyway
@@ -133,50 +130,43 @@ public class UpdateAttributesProcessor {
if (!advisor.isInitialized()) {
// no need to tell the other guy we are going away since
// never got initialized.
- return;
+ return null;
}
} else if (advisor.initializationGate()) {
// it just did the profile exchange so we are done
- return;
+ return null;
}
}
- final Set recipients;
- if (this.removeProfile) {
- recipients = advisor.adviseProfileRemove();
- } else if (exchangeProfiles) {
- recipients = advisor.adviseProfileExchange();
- } else {
- recipients = advisor.adviseProfileUpdate();
- }
-
+ final Set recipients = determineRecipients(exchangeProfiles, advisor);
if (recipients.isEmpty()) {
- return;
+ return null;
}
// always require an ack to prevent misordering of messages
InternalDistributedSystem system = this.advisee.getSystem();
UpdateAttributesReplyProcessor replyProcessor =
new UpdateAttributesReplyProcessor(system, recipients);
- UpdateAttributesMessage message = getUpdateAttributesMessage(replyProcessor);
+ UpdateAttributesMessage message = getUpdateAttributesMessage(replyProcessor, exchangeProfiles);
mgr.putOutgoing(message);
- this.processor = replyProcessor;
+ return replyProcessor;
}
- UpdateAttributesMessage getUpdateAttributesMessage(UpdateAttributesReplyProcessor processor) {
-
- UpdateAttributesMessage msg = new UpdateAttributesMessage();
- msg.adviseePath = this.advisee.getFullPath();
- msg.setRecipients(processor.getRecipients());
- msg.processorId = processor.getProcessorId();
- msg.profile = this.advisee.getProfile();
- msg.exchangeProfiles = this.profileExchange;
- msg.removeProfile = this.removeProfile;
- return msg;
+ private Set determineRecipients(boolean exchangeProfiles, DistributionAdvisor advisor) {
+ if (this.removeProfile) {
+ return advisor.adviseProfileRemove();
+ } else if (exchangeProfiles) {
+ return advisor.adviseProfileExchange();
+ } else {
+ return advisor.adviseProfileUpdate();
+ }
}
- public void validateProfiles() {
-
+ private UpdateAttributesMessage getUpdateAttributesMessage(
+ UpdateAttributesReplyProcessor processor, boolean exchangeProfiles) {
+ return new UpdateAttributesMessage(this.advisee.getFullPath(), processor.getRecipients(),
+ processor.getProcessorId(), this.advisee.getProfile(), exchangeProfiles,
+ this.removeProfile);
}
class UpdateAttributesReplyProcessor extends ReplyProcessor21 {
@@ -259,15 +249,26 @@ public class UpdateAttributesProcessor {
}
}
-
public static class UpdateAttributesMessage extends HighPriorityDistributionMessage
implements MessageWithReply {
- protected String adviseePath;
- protected int processorId = 0;
+ String adviseePath;
+ protected int processorId;
protected Profile profile;
- protected boolean exchangeProfiles = false;
- protected boolean removeProfile = false;
+ boolean exchangeProfiles;
+ boolean removeProfile;
+
+ public UpdateAttributesMessage() {}
+
+ public UpdateAttributesMessage(String adviseePath, Collection recipients, int processorId,
+ Profile profile, boolean exchangeProfiles, boolean removeProfile) {
+ this.adviseePath = adviseePath;
+ this.setRecipients(recipients);
+ this.processorId = processorId;
+ this.profile = profile;
+ this.exchangeProfiles = exchangeProfiles;
+ this.removeProfile = removeProfile;
+ }
@Override
public int getProcessorId() {
@@ -287,7 +288,7 @@ public class UpdateAttributesProcessor {
try {
if (this.profile != null) {
if (this.exchangeProfiles) {
- replyProfiles = new ArrayList<Profile>();
+ replyProfiles = new ArrayList<>();
}
this.profile.processIncoming(dm, this.adviseePath, this.removeProfile,
this.exchangeProfiles, replyProfiles);
@@ -333,7 +334,7 @@ public class UpdateAttributesProcessor {
@Override
public String toString() {
StringBuilder buff = new StringBuilder();
- buff.append("UpdateAttributesMessage (adviseePath=");
+ buff.append(this.getClass().getName() + " (adviseePath=");
buff.append(this.adviseePath);
buff.append("; processorId=");
buff.append(this.processorId);
@@ -377,7 +378,6 @@ public class UpdateAttributesProcessor {
}
}
-
public static class ProfileReplyMessage extends ReplyMessage {
Profile profile;
@@ -509,6 +509,7 @@ public class UpdateAttributesProcessor {
final StringBuilder buff = new StringBuilder();
buff.append("ProfilesReplyMessage");
buff.append(" (processorId=");
+
buff.append(super.processorId);
if (this.profiles != null) {
buff.append("; profiles=");
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ValidateCacheServerProfileProcessor.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ValidateCacheServerProfileProcessor.java
new file mode 100644
index 0000000..2af38f2
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/ValidateCacheServerProfileProcessor.java
@@ -0,0 +1,357 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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.apache.geode.internal.cache;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.DistributionAdvisee;
+import org.apache.geode.distributed.internal.DistributionAdvisor;
+import org.apache.geode.distributed.internal.DistributionAdvisor.Profile;
+import org.apache.geode.distributed.internal.DistributionManager;
+import org.apache.geode.distributed.internal.DistributionMessage;
+import org.apache.geode.distributed.internal.HighPriorityDistributionMessage;
+import org.apache.geode.distributed.internal.MessageWithReply;
+import org.apache.geode.distributed.internal.ReplyException;
+import org.apache.geode.distributed.internal.ReplyMessage;
+import org.apache.geode.distributed.internal.ReplyProcessor21;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.logging.LogService;
+
+public class ValidateCacheServerProfileProcessor {
+ private static final Logger logger = LogService.getLogger();
+
+ protected final DistributionAdvisee advisee;
+
+ public ValidateCacheServerProfileProcessor(DistributionAdvisee distributionAdvisee) {
+ this.advisee = distributionAdvisee;
+ }
+
+ private ValidateCacheProfileMessage getValidateCacheProfileMessage(
+ ValidateProfileUpdateReplyProcessor processor) {
+ ValidateCacheProfileMessage validateCacheProfileMessage =
+ new ValidateCacheProfileMessage(this.advisee.getFullPath(), processor.getRecipients(),
+ processor.getProcessorId(), this.advisee.getProfile());
+ return validateCacheProfileMessage;
+ }
+
+ void validateCacheServerProfiles() throws IncompatibleCacheServiceProfileException {
+ final Set recipients = this.advisee.getDistributionAdvisor().adviseProfileUpdate();
+
+ if (recipients.isEmpty()) {
+ return;
+ }
+
+ ValidateProfileUpdateReplyProcessor replyProcessor =
+ new ValidateProfileUpdateReplyProcessor(this.advisee, recipients);
+ ValidateCacheProfileMessage message = getValidateCacheProfileMessage(replyProcessor);
+ this.advisee.getDistributionManager().putOutgoing(message);
+ waitForProfileResponse(replyProcessor);
+ }
+
+ public void waitForProfileResponse(ReplyProcessor21 processor)
+ throws IncompatibleCacheServiceProfileException {
+ if (processor == null) {
+ return;
+ }
+ DistributionManager mgr = this.advisee.getDistributionManager();
+ try {
+ // bug 36983 - you can't loop on a reply processor
+ mgr.getCancelCriterion().checkCancelInProgress(null);
+ try {
+ processor.waitForRepliesUninterruptibly();
+ } catch (ReplyException e) {
+ if (e.getCause() instanceof IncompatibleCacheServiceProfileException) {
+ throw (IncompatibleCacheServiceProfileException) e.getCause();
+ }
+ }
+ } finally {
+ processor.cleanup();
+ }
+ }
+
+ class ValidateProfileUpdateReplyProcessor extends ReplyProcessor21 {
+
+ private final DistributionAdvisee advisee;
+
+ ValidateProfileUpdateReplyProcessor(DistributionAdvisee advisee, Set members) {
+ super(advisee.getSystem(), members);
+ this.advisee = advisee;
+ }
+
+ /**
+ * Registers this processor as a membership listener and returns a set of the current members.
+ *
+ * @return a Set of the current members
+ * @since Geode 1.7
+ */
+ @Override
+ protected Set addListenerAndGetMembers() {
+ DistributionAdvisor da = this.advisee.getDistributionAdvisor();
+ if (da.useAdminMembersForDefault()) {
+ return getDistributionManager().addAllMembershipListenerAndGetAllIds(this);
+ } else {
+ return super.addListenerAndGetMembers();
+ }
+ }
+
+ /**
+ * Unregisters this processor as a membership listener
+ *
+ * @since Geode 1.7
+ */
+ @Override
+ protected void removeListener() {
+ DistributionAdvisor da = this.advisee.getDistributionAdvisor();
+ if (da.useAdminMembersForDefault()) {
+ getDistributionManager().removeAllMembershipListener(this);
+ } else {
+ super.removeListener();
+ }
+ }
+
+ /**
+ * If this processor being used by controller then return ALL members; otherwise defer to super.
+ *
+ * @return a Set of the current members
+ * @since Geode 1.7
+ */
+ @Override
+ protected Set getDistributionManagerIds() {
+ DistributionAdvisor da = this.advisee.getDistributionAdvisor();
+ if (da.useAdminMembersForDefault()) {
+ return getDistributionManager().getDistributionManagerIdsIncludingAdmin();
+ } else {
+ return super.getDistributionManagerIds();
+ }
+ }
+
+ public Collection getRecipients() {
+ return Arrays.asList(members);
+ }
+
+ @Override
+ public void process(DistributionMessage msg) {
+ try {
+ // TODO UDO: Check if something needs to be done here
+ ValidateCacheServerProfileReplyMessage validateCacheServerProfileReplyMessage =
+ (ValidateCacheServerProfileReplyMessage) msg;
+ // if (msg instanceof ProfilesReplyMessage) {
+ // ProfilesReplyMessage reply = (ProfilesReplyMessage) msg;
+ // if (reply.profiles != null) {
+ // Arrays.stream(reply.profiles)
+ // .forEach((profile) -> ValidateCacheServerProfileProcessor.this.advisee
+ // .getDistributionAdvisor().putProfile(profile));
+ // }
+ // } else if (msg instanceof ProfileReplyMessage) {
+ // ProfileReplyMessage reply = (ProfileReplyMessage) msg;
+ // if (reply.profile != null) {
+ // if (advisee instanceof LocalRegion && reply.profile instanceof CacheServiceProfile) {
+ // LocalRegion localRegion = (LocalRegion) advisee;
+ // Map<String, CacheServiceProfile> cacheServiceProfiles =
+ // localRegion.getCacheServiceProfiles();
+ // CacheServiceProfile
+ // cacheServiceProfile =
+ // cacheServiceProfiles.get(reply.profile.getId());
+ // if (cacheServiceProfile != null) {
+ // String result =
+ // cacheServiceProfile.checkCompatibility(localRegion.getFullPath(),
+ // (CacheServiceProfile) reply.profile);
+ // if (result != null) {
+ // if (logger.isDebugEnabled()) {
+ // logger.debug("{} <replyProfile not set because errorMsg={}", this, result);
+ // }
+ // ReplyException
+ // replyException =
+ // new ReplyException(new IllegalStateException(result));
+ // reply.setException(replyException);
+ // }
+ // }
+ // }
+ // }
+ // }
+ } finally {
+ super.process(msg);
+ }
+ }
+ }
+
+ public static class ValidateCacheProfileMessage extends HighPriorityDistributionMessage
+ implements MessageWithReply {
+
+ private String adviseePath;
+ private int processorId;
+ private Profile profile;
+
+ public ValidateCacheProfileMessage() {}
+
+ ValidateCacheProfileMessage(String adviseePath, Collection recipients, int processorId,
+ Profile profile) {
+ this.adviseePath = adviseePath;
+ this.setRecipients(recipients);
+ this.processorId = processorId;
+ this.profile = profile;
+ }
+
+ @Override
+ protected void process(ClusterDistributionManager dm) {
+ if (adviseePath != null) {
+ LocalRegion region = (LocalRegion) dm.getCache().getRegion(adviseePath);
+ String compatibility = checkCacheServerProfileCompatibility(region,
+ (CacheDistributionAdvisor.CacheProfile) this.profile);
+
+ ReplyException replyException = (compatibility != null
+ ? new ReplyException(new IncompatibleCacheServiceProfileException(compatibility))
+ : null);
+ ValidateCacheServerProfileReplyMessage.send(getSender(), this.processorId, replyException,
+ dm);
+ }
+ }
+
+ private String checkCacheServerProfileCompatibility(LocalRegion localRegion,
+ CacheDistributionAdvisor.CacheProfile cacheProfile) {
+ String cspResult = null;
+ Map<String, CacheServiceProfile> myProfiles = localRegion.getCacheServiceProfiles();
+ // Iterate and compare the remote CacheServiceProfiles to the local ones
+ for (CacheServiceProfile remoteProfile : cacheProfile.cacheServiceProfiles) {
+ CacheServiceProfile localProfile = myProfiles.get(remoteProfile.getId());
+ if (localProfile != null) {
+ cspResult = remoteProfile.checkCompatibility(localRegion.getFullPath(), localProfile);
+ }
+ if (cspResult != null) {
+ return cspResult;
+ }
+ }
+ return cspResult;
+ }
+
+ public int getDSFID() {
+ return VALIDATE_CACHE_PROFILE_MESSAGE;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buff = new StringBuilder();
+ buff.append(this.getClass().getName() + " (adviseePath=");
+ buff.append(this.adviseePath);
+ buff.append("; processorId=");
+ buff.append(this.processorId);
+ buff.append("; profile=");
+ buff.append(this.profile);
+ buff.append(")");
+ return buff.toString();
+ }
+
+ @Override
+ public void fromData(DataInput in) throws IOException, ClassNotFoundException {
+ super.fromData(in);
+ this.adviseePath = DataSerializer.readString(in);
+ this.processorId = in.readInt();
+ // set the processor ID to be able to send reply to sender in case of any
+ // unexpected exception during deserialization etc.
+ ReplyProcessor21.setMessageRPId(this.processorId);
+ this.profile = DataSerializer.readObject(in);
+ }
+
+ @Override
+ public void toData(DataOutput out) throws IOException {
+ super.toData(out);
+ DataSerializer.writeString(this.adviseePath, out);
+ out.writeInt(this.processorId);
+ DataSerializer.writeObject(this.profile, out);
+ }
+ }
+
+ public static class ValidateCacheServerProfileReplyMessage extends ReplyMessage {
+
+ public static void send(InternalDistributedMember recipient, int processorId,
+ ReplyException exception, ClusterDistributionManager dm) {
+ ValidateCacheServerProfileReplyMessage m = new ValidateCacheServerProfileReplyMessage();
+
+ m.processorId = processorId;
+ if (exception != null) {
+ m.setException(exception);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Replying with exception: {}" + m, exception);
+ }
+ }
+ m.setRecipient(recipient);
+ dm.putOutgoing(m);
+ }
+
+ @Override
+ public int getDSFID() {
+ return VALIDATE_CACHE_SERVER_REPLY_MESSAGE;
+ }
+
+ @Override
+ public void fromData(DataInput in) throws IOException, ClassNotFoundException {
+ super.fromData(in);
+ }
+
+ @Override
+ public void toData(DataOutput out) throws IOException {
+ super.toData(out);
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder buff = new StringBuilder();
+ buff.append(this.getClass().getName());
+ buff.append(" (processorId=");
+ buff.append(super.processorId);
+ buff.append(")");
+ return buff.toString();
+ }
+
+ @Override
+ public boolean getInlineProcess() {
+ return true;
+ }
+ }
+
+ public static class ValidateCacheServerProfileReplyException extends ReplyException {
+ public ValidateCacheServerProfileReplyException() {
+ super();
+ }
+
+ public ValidateCacheServerProfileReplyException(String msg) {
+ super(msg);
+ }
+
+ public ValidateCacheServerProfileReplyException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+ public ValidateCacheServerProfileReplyException(Throwable cause) {
+ super(cause);
+ }
+
+ @Override
+ public void handleCause() {
+ super.handleCause();
+ }
+ }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/DUnitLauncher.java b/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/DUnitLauncher.java
index a61b609..3cdb008 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/DUnitLauncher.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/standalone/DUnitLauncher.java
@@ -149,6 +149,15 @@ public class DUnitLauncher {
/**
* Launch DUnit. If the unit test was launched through the hydra framework, leave the test alone.
*/
+ public static void launchIfNeeded(int vmCount) {
+ NUM_VMS = vmCount;
+ launchIfNeeded();
+ }
+
+
+ /**
+ * Launch DUnit. If the unit test was launched through the hydra framework, leave the test alone.
+ */
public static void launchIfNeeded() {
if (System.getProperties().contains(VM_NUM_PARAM)) {
// we're a dunit child vm, do nothing.
@@ -167,14 +176,6 @@ public class DUnitLauncher {
}
/**
- * Launch DUnit. If the unit test was launched through the hydra framework, leave the test alone.
- */
- public static void launchIfNeeded(int vmCount) {
- NUM_VMS = vmCount;
- launchIfNeeded();
- }
-
- /**
* Test it see if the eclise dunit environment is launched.
*/
public static boolean isLaunched() {
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfile.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfile.java
index 3d9b00d..c4a0b67 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfile.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexCreationProfile.java
@@ -102,6 +102,7 @@ public class LuceneIndexCreationProfile implements CacheServiceProfile, Versione
@Override
public String checkCompatibility(String regionPath, CacheServiceProfile profile) {
String result = null;
+
LuceneIndexCreationProfile remoteProfile = (LuceneIndexCreationProfile) profile;
// Verify fields are the same
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index 1a86d32..b378328 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -141,7 +140,8 @@ public class LuceneServiceImpl implements InternalLuceneService {
public void beforeRegionDestroyed(Region region) {
List<LuceneIndex> indexes = getIndexes(region.getFullPath());
if (!indexes.isEmpty()) {
- String indexNames = indexes.stream().map(i -> i.getName()).collect(Collectors.joining(","));
+ String indexNames =
+ indexes.stream().map(LuceneIndex::getName).collect(Collectors.joining(","));
throw new IllegalStateException(
LocalizedStrings.LuceneServiceImpl_REGION_0_CANNOT_BE_DESTROYED
.toLocalizedString(region.getFullPath(), indexNames));
@@ -245,11 +245,14 @@ public class LuceneServiceImpl implements InternalLuceneService {
LuceneSerializer serializer) {
validateRegionAttributes(region.getAttributes());
+ LuceneIndexCreationProfile profile = new LuceneIndexCreationProfile(indexName, regionPath,
+ fields, analyzer, fieldAnalyzers, serializer);
try {
- region.addCacheServiceProfile(new LuceneIndexCreationProfile(indexName, regionPath, fields,
- analyzer, fieldAnalyzers, serializer));
+ region.addCacheServiceProfile(profile);
} catch (IncompatibleCacheServiceProfileException e) {
- e.printStackTrace();
+ logger.error(e);
+ region.removeCacheServiceProfile(profile);
+ throw new IllegalStateException(e);
}
String aeqId = LuceneServiceImpl.getUniqueIndexName(indexName, regionPath);
@@ -271,9 +274,7 @@ public class LuceneServiceImpl implements InternalLuceneService {
PartitionedRepositoryManager repositoryManager =
(PartitionedRepositoryManager) luceneIndex.getRepositoryManager();
Set<Integer> primaryBucketIds = userRegion.getDataStore().getAllLocalPrimaryBucketIds();
- Iterator primaryBucketIterator = primaryBucketIds.iterator();
- while (primaryBucketIterator.hasNext()) {
- int primaryBucketId = (Integer) primaryBucketIterator.next();
+ for (Integer primaryBucketId : primaryBucketIds) {
try {
BucketRegion userBucket = userRegion.getDataStore().getLocalBucketById(primaryBucketId);
if (userBucket == null) {
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/EvictionDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/EvictionDUnitTest.java
index 15bb6d5..8aa477f 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/EvictionDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/EvictionDUnitTest.java
@@ -18,7 +18,6 @@ import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.INDEX_NAME;
import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -27,6 +26,7 @@ import java.util.stream.IntStream;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.awaitility.Awaitility;
+import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
@@ -46,10 +46,10 @@ import org.apache.geode.test.junit.categories.LuceneTest;
@RunWith(JUnitParamsRunner.class)
public class EvictionDUnitTest extends LuceneQueriesAccessorBase {
- protected static final float INITIAL_EVICTION_HEAP_PERCENTAGE = 50.9f;
- protected static final float EVICTION_HEAP_PERCENTAGE_FAKE_NOTIFICATION = 85.0f;
- protected static final int TEST_MAX_MEMORY = 100;
- protected static final int MEMORY_USED_FAKE_NOTIFICATION = 90;
+ private static final float INITIAL_EVICTION_HEAP_PERCENTAGE = 50.9f;
+ private static final float EVICTION_HEAP_PERCENTAGE_FAKE_NOTIFICATION = 85.0f;
+ private static final int TEST_MAX_MEMORY = 100;
+ private static final int MEMORY_USED_FAKE_NOTIFICATION = 90;
protected RegionTestableType[] getPartitionRedundantOverflowEvictionRegionType() {
return new RegionTestableType[] {
@@ -63,6 +63,13 @@ public class EvictionDUnitTest extends LuceneQueriesAccessorBase {
RegionTestableType.PARTITION_PERSISTENT_EVICTION_LOCAL_DESTROY};
}
+ @Before
+ public void init() {
+ dataStore1.invoke(() -> cacheRule.createCache(getDistributedSystemProperties()));
+ accessor.invoke(() -> cacheRule.createCache(getDistributedSystemProperties()));
+ // dataStore2.invoke(() -> cacheRule.createCache(getDistributedSystemProperties()));
+ }
+
@Test
@Parameters(method = "getPartitionRedundantLocalDestroyEvictionRegionType")
public void regionWithEvictionWithLocalDestroyMustNotbeAbleToCreateLuceneIndexes(
@@ -107,15 +114,16 @@ public class EvictionDUnitTest extends LuceneQueriesAccessorBase {
Region region = cache.getRegion(REGION_NAME);
IntStream.range(0, NUM_BUCKETS).forEach(i -> region.put(i, new TestObject("hello world")));
});
- waitForFlushBeforeExecuteTextSearch(accessor, 60000);
+
+ accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000));
dataStore1.invoke(() -> {
try {
getCache().getResourceManager().setEvictionHeapPercentage(INITIAL_EVICTION_HEAP_PERCENTAGE);
- final PartitionedRegion partitionedRegion = (PartitionedRegion) getRootRegion(REGION_NAME);
+ final PartitionedRegion partitionedRegion =
+ (PartitionedRegion) getCache().getRegion(REGION_NAME);
raiseFakeNotification();
- Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
- assertTrue(partitionedRegion.getDiskRegionStats().getNumOverflowOnDisk() > 0);
- });
+ Awaitility.await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(120, TimeUnit.SECONDS)
+ .until(() -> partitionedRegion.getDiskRegionStats().getNumOverflowOnDisk() > 0);
} finally {
cleanUpAfterFakeNotification();
}
@@ -131,21 +139,20 @@ public class EvictionDUnitTest extends LuceneQueriesAccessorBase {
}
- protected void raiseFakeNotification() {
+ private void raiseFakeNotification() {
((GemFireCacheImpl) getCache()).getHeapEvictor().setTestAbortAfterLoopCount(1);
HeapMemoryMonitor.setTestDisableMemoryUpdates(true);
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "memoryEventTolerance", "0");
getCache().getResourceManager()
.setEvictionHeapPercentage(EVICTION_HEAP_PERCENTAGE_FAKE_NOTIFICATION);
- HeapMemoryMonitor heapMemoryMonitor =
- ((GemFireCacheImpl) getCache()).getInternalResourceManager().getHeapMonitor();
+ HeapMemoryMonitor heapMemoryMonitor = getCache().getInternalResourceManager().getHeapMonitor();
heapMemoryMonitor.setTestMaxMemoryBytes(TEST_MAX_MEMORY);
heapMemoryMonitor.updateStateAndSendEvent(MEMORY_USED_FAKE_NOTIFICATION);
}
- protected void cleanUpAfterFakeNotification() {
+ private void cleanUpAfterFakeNotification() {
((GemFireCacheImpl) getCache()).getHeapEvictor().setTestAbortAfterLoopCount(Integer.MAX_VALUE);
HeapMemoryMonitor.setTestDisableMemoryUpdates(false);
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "memoryEventTolerance");
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/ExpirationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/ExpirationDUnitTest.java
index 3e2aab9..20b92a0 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/ExpirationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/ExpirationDUnitTest.java
@@ -41,7 +41,7 @@ import org.apache.geode.test.junit.categories.LuceneTest;
@RunWith(JUnitParamsRunner.class)
public class ExpirationDUnitTest extends LuceneQueriesAccessorBase {
- protected static final int EXTRA_WAIT_TIME_SEC = 15;
+ private static final int EXTRA_WAIT_TIME_SEC = 15;
protected RegionTestableType[] getPartitionRegionsWithExpirationSet() {
return new RegionTestableType[] {RegionTestableType.PARTITION_WITH_EXPIRATION_DESTROY,
@@ -68,7 +68,7 @@ public class ExpirationDUnitTest extends LuceneQueriesAccessorBase {
IntStream.range(0, NUM_BUCKETS).forEach(i -> region.put(i, new TestObject("hello world")));
});
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
accessor.invoke(() -> Awaitility.await()
.atMost(EXPIRATION_TIMEOUT_SEC + EXTRA_WAIT_TIME_SEC, TimeUnit.SECONDS).until(() -> {
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityDUnitTest.java
index 06cf7c1..30ede2a 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityDUnitTest.java
@@ -29,6 +29,8 @@ import java.util.concurrent.TimeUnit;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
+import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
@@ -36,7 +38,6 @@ import org.junit.runner.RunWith;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.ServerOperationException;
@@ -45,6 +46,8 @@ import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.security.NotAuthorizedException;
import org.apache.geode.security.SimpleTestSecurityManager;
import org.apache.geode.security.templates.UserPasswordAuthInit;
+import org.apache.geode.test.dunit.rules.ClientCacheRule;
+import org.apache.geode.test.dunit.rules.DistributedTestRule;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.categories.LuceneTest;
import org.apache.geode.test.junit.categories.SecurityTest;
@@ -53,13 +56,19 @@ import org.apache.geode.test.junit.categories.SecurityTest;
@RunWith(JUnitParamsRunner.class)
public class LuceneClientSecurityDUnitTest extends LuceneQueriesAccessorBase {
+ @ClassRule
+ public static DistributedTestRule distributedTestRule = new DistributedTestRule(3);
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
@Test
@Parameters(method = "getSearchIndexUserNameAndExpectedResponses")
public void verifySearchIndexPermissions(
LuceneCommandsSecurityDUnitTest.UserNameAndExpectedResponse user) {
// Start server
- int serverPort = dataStore1.invoke(() -> startCacheServer());
- dataStore1.invoke(() -> createRegionIndexAndData());
+ int serverPort = dataStore1.invoke(this::startCacheServer);
+ dataStore1.invoke(this::createRegionIndexAndData);
// Start client
accessor.invoke(() -> startClient(user.getUserName(), serverPort));
@@ -82,8 +91,8 @@ public class LuceneClientSecurityDUnitTest extends LuceneQueriesAccessorBase {
props.put(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
"org.apache.geode.cache.lucene.test.TestObject");
props.setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName());
- final Cache cache = getCache(props);
- final CacheServer server = cache.addCacheServer();
+ cacheRule.createCache(props);
+ final CacheServer server = cacheRule.getCache().addCacheServer();
server.setPort(0);
server.start();
return server.getPort();
@@ -98,13 +107,14 @@ public class LuceneClientSecurityDUnitTest extends LuceneQueriesAccessorBase {
props.setProperty(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName());
ClientCacheFactory clientCacheFactory = new ClientCacheFactory(props);
clientCacheFactory.addPoolServer("localhost", serverPort);
- ClientCache clientCache = getClientCache(clientCacheFactory);
- clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(REGION_NAME);
+ clientCacheRule.createClientCache(clientCacheFactory);
+ clientCacheRule.getClientCache().createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
+ .create(REGION_NAME);
}
private void executeTextSearch(boolean expectAuthorizationError, String expectedResponse)
throws LuceneQueryException, InterruptedException {
- LuceneService service = LuceneServiceProvider.get(getCache());
+ LuceneService service = LuceneServiceProvider.get(clientCacheRule.getClientCache());
LuceneQuery<Integer, TestObject> query =
service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "hello", "field1");
try {
@@ -118,7 +128,6 @@ public class LuceneClientSecurityDUnitTest extends LuceneQueriesAccessorBase {
assertThat(e.getCause()).hasCauseInstanceOf(NotAuthorizedException.class);
}
-
try {
List<LuceneResultStruct<Integer, TestObject>> results = query.findResults();
assertEquals(1, results.size());
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
index 479f884..66de6d2 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
@@ -16,8 +16,13 @@ package org.apache.geode.cache.lucene;
import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
+import java.io.Serializable;
import java.util.Properties;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.EvictionAction;
import org.apache.geode.cache.EvictionAttributes;
@@ -29,36 +34,44 @@ import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.SerializableRunnableIF;
import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
+import org.apache.geode.test.dunit.rules.CacheRule;
+import org.apache.geode.test.dunit.rules.DistributedTestRule;
-public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
- protected VM dataStore1;
- protected VM dataStore2;
+public abstract class LuceneDUnitTest implements Serializable {
+ @ClassRule
+ public static DistributedTestRule distributedTestRule = new DistributedTestRule(2);
- protected static int NUM_BUCKETS = 10;
- protected static int MAX_ENTRIES_FOR_EVICTION = 20;
- protected static int EXPIRATION_TIMEOUT_SEC = 5;
+ @Rule
+ public CacheRule cacheRule = new CacheRule();
- @Override
- public void postSetUp() throws Exception {
+ @Before
+ public void initialize() {
Host host = Host.getHost(0);
dataStore1 = host.getVM(0);
dataStore2 = host.getVM(1);
}
+ protected VM dataStore1;
+ protected VM dataStore2;
+
+ static int NUM_BUCKETS = 10;
+ private static int MAX_ENTRIES_FOR_EVICTION = 20;
+ static int EXPIRATION_TIMEOUT_SEC = 5;
+
+ protected InternalCache getCache() {
+ return cacheRule.getCache();
+ }
+
protected void initDataStore(SerializableRunnableIF createIndex,
- RegionTestableType regionTestType) throws Exception {
+ RegionTestableType regionTestType) throws Exception {
+ cacheRule.getOrCreateCache();
createIndex.run();
regionTestType.createDataStore(getCache(), REGION_NAME);
- }
- protected void initAccessor(SerializableRunnableIF createIndex, RegionTestableType regionTestType)
- throws Exception {
- createIndex.run();
- regionTestType.createAccessor(getCache(), REGION_NAME);
}
protected void initDataStore(RegionTestableType regionTestType) throws Exception {
@@ -70,7 +83,7 @@ public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
}
protected RegionTestableType[] getListOfRegionTestTypes() {
- return new RegionTestableType[] {RegionTestableType.PARTITION,
+ return new RegionTestableType[]{RegionTestableType.PARTITION,
RegionTestableType.PARTITION_REDUNDANT, RegionTestableType.PARTITION_OVERFLOW_TO_DISK,
RegionTestableType.PARTITION_PERSISTENT, RegionTestableType.FIXED_PARTITION};
}
@@ -79,15 +92,14 @@ public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
Object[] parameters = new Object[aValues.length * bValues.length];
for (int i = 0; i < aValues.length; i++) {
for (int j = 0; j < bValues.length; j++) {
- parameters[i * bValues.length + j] = new Object[] {aValues[i], bValues[j]};
+ parameters[i * bValues.length + j] = new Object[]{aValues[i], bValues[j]};
}
}
return parameters;
}
- @Override
- public Properties getDistributedSystemProperties() {
- Properties result = super.getDistributedSystemProperties();
+ protected Properties getDistributedSystemProperties() {
+ Properties result = new Properties();
result.put(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
"org.apache.geode.cache.lucene.test.TestObject;org.apache.geode.cache.lucene.LuceneQueriesAccessorBase$TestObject"
+ ";org.apache.geode.cache.lucene.LuceneDUnitTest"
@@ -112,16 +124,16 @@ public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK)),
PARTITION_REDUNDANT_EVICTION_LOCAL_DESTROY(RegionShortcut.PARTITION_PROXY_REDUNDANT,
RegionShortcut.PARTITION_REDUNDANT, EvictionAttributes
- .createLRUEntryAttributes(MAX_ENTRIES_FOR_EVICTION, EvictionAction.LOCAL_DESTROY)),
+ .createLRUEntryAttributes(MAX_ENTRIES_FOR_EVICTION, EvictionAction.LOCAL_DESTROY)),
PARTITION_REDUNDANT_PERSISTENT_EVICTION_LOCAL_DESTROY(RegionShortcut.PARTITION_PROXY_REDUNDANT,
RegionShortcut.PARTITION_REDUNDANT_PERSISTENT, EvictionAttributes
- .createLRUEntryAttributes(MAX_ENTRIES_FOR_EVICTION, EvictionAction.LOCAL_DESTROY)),
+ .createLRUEntryAttributes(MAX_ENTRIES_FOR_EVICTION, EvictionAction.LOCAL_DESTROY)),
PARTITION_EVICTION_LOCAL_DESTROY(RegionShortcut.PARTITION_PROXY, RegionShortcut.PARTITION,
EvictionAttributes.createLRUEntryAttributes(MAX_ENTRIES_FOR_EVICTION,
EvictionAction.LOCAL_DESTROY)),
PARTITION_PERSISTENT_EVICTION_LOCAL_DESTROY(RegionShortcut.PARTITION_PROXY,
RegionShortcut.PARTITION_PERSISTENT, EvictionAttributes
- .createLRUEntryAttributes(MAX_ENTRIES_FOR_EVICTION, EvictionAction.LOCAL_DESTROY)),
+ .createLRUEntryAttributes(MAX_ENTRIES_FOR_EVICTION, EvictionAction.LOCAL_DESTROY)),
PARTITION_REDUNDANT_WITH_EXPIRATION_DESTROY(RegionShortcut.PARTITION_PROXY_REDUNDANT,
RegionShortcut.PARTITION_REDUNDANT, EXPIRATION_TIMEOUT_SEC, ExpirationAction.DESTROY),
PARTITION_WITH_EXPIRATION_DESTROY(RegionShortcut.PARTITION_PROXY, RegionShortcut.PARTITION,
@@ -143,19 +155,20 @@ public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
}
RegionTestableType(RegionShortcut clientRegionShortcut, RegionShortcut serverRegionShortcut,
- EvictionAttributes evictionAttributes) {
+ EvictionAttributes evictionAttributes) {
this(clientRegionShortcut, serverRegionShortcut, evictionAttributes, null, NUM_BUCKETS);
}
RegionTestableType(RegionShortcut clientRegionShortcut, RegionShortcut serverRegionShortcut,
- int timeout, ExpirationAction expirationAction) {
+ int timeout, ExpirationAction expirationAction) {
this(clientRegionShortcut, serverRegionShortcut, null,
new ExpirationAttributes(timeout, expirationAction), NUM_BUCKETS);
}
RegionTestableType(RegionShortcut clientRegionShortcut, RegionShortcut serverRegionShortcut,
- EvictionAttributes evictionAttributes, ExpirationAttributes expirationAttributes,
- int numBuckets) {
+ EvictionAttributes evictionAttributes,
+ ExpirationAttributes expirationAttributes,
+ int numBuckets) {
this.clientRegionShortcut = clientRegionShortcut;
this.serverRegionShortcut = serverRegionShortcut;
this.evictionAttributes = evictionAttributes;
@@ -204,8 +217,8 @@ public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
}
}
- protected static PartitionAttributes getPartitionAttributes(final boolean isAccessor,
- final int numBuckets) {
+ private static PartitionAttributes getPartitionAttributes(final boolean isAccessor,
+ final int numBuckets) {
PartitionAttributesFactory factory = new PartitionAttributesFactory();
if (isAccessor) {
factory.setLocalMaxMemory(0);
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
index 0a09934..0a40a95 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
@@ -14,7 +14,6 @@
*/
package org.apache.geode.cache.lucene;
-import static junitparams.JUnitParamsRunner.$;
import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_ANALYZERS;
import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_ANALYZERS_2;
import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_FIELDS;
@@ -44,6 +43,7 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.hamcrest.Matchers;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -77,7 +77,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
}
protected Object[] parametersForIndexAndRegions() {
- Object[] indexCreations = new Object[] {getFieldsIndexWithOneField(),
+ Object[] indexCreations = new Object[]{getFieldsIndexWithOneField(),
getFieldsIndexWithTwoFields(), get2FieldsIndexes(), getAnalyzersIndexWithOneField(),
getAnalyzersIndexWithTwoFields(), getAnalyzersIndexWithNullField1()};
RegionTestableType[] regionTestTypes = getListOfRegionTestTypes();
@@ -87,7 +87,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
@Test
@Parameters(method = "parametersForMultipleIndexCreates")
public void verifyThatIndexObjectsAreListedWhenPresentInTheSystem(int numberOfIndexes,
- RegionTestableType regionType) {
+ RegionTestableType regionType) {
SerializableRunnableIF createIndex = getMultipleIndexes(numberOfIndexes);
dataStore1.invoke(() -> initDataStore(createIndex, regionType));
dataStore1.invoke(() -> verifyIndexList(numberOfIndexes));
@@ -99,7 +99,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
@Test
@Parameters(method = "parametersForMultipleIndexCreates")
public void verifyThatIndexObjectIsRetrievedWhenPresentInTheSystem(int numberOfIndexes,
- RegionTestableType regionType) {
+ RegionTestableType regionType) {
SerializableRunnableIF createIndex = getMultipleIndexes(numberOfIndexes);
dataStore1.invoke(() -> initDataStore(createIndex, regionType));
dataStore1.invoke(() -> verifyIndexes(numberOfIndexes));
@@ -117,11 +117,13 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
@Test
public void verifyNullIsReturnedWhenGetIndexIsCalledAndNoIndexesArePresent() {
dataStore1.invoke(() -> {
+ cacheRule.createCache();
LuceneService luceneService = LuceneServiceProvider.get(getCache());
assertNull(luceneService.getIndex(INDEX_NAME, REGION_NAME));
});
dataStore2.invoke(() -> {
+ cacheRule.createCache();
LuceneService luceneService = LuceneServiceProvider.get(getCache());
assertNull(luceneService.getIndex(INDEX_NAME, REGION_NAME));
});
@@ -234,7 +236,8 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
dataStore1.invoke(() -> initDataStore(createIndex1, regionType));
SerializableRunnableIF createIndex2 = () -> {
- /* Do nothing */};
+ /* Do nothing */
+ };
dataStore2.invoke(() -> initDataStore(createIndex2, regionType,
CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_INDEXES_1));
}
@@ -258,9 +261,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
@Test
@Parameters({"PARTITION"})
public void verifyMemberWithoutIndexCreatedFirstFails(RegionTestableType regionType) {
- SerializableRunnableIF createIndex1 = () -> {
- /* Do nothing */};
- dataStore1.invoke(() -> initDataStore(createIndex1, regionType));
+ dataStore1.invoke(() -> initDataStore(() -> {}, regionType));
SerializableRunnableIF createIndex2 = getFieldsIndexWithOneField();
dataStore2.invoke(() -> initDataStore(createIndex2, regionType,
@@ -270,7 +271,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
@Test
@Parameters(method = "parametersForIndexAndRegions")
public void verifySameIndexesSucceeds(SerializableRunnableIF createIndex,
- RegionTestableType regionType) {
+ RegionTestableType regionType) {
dataStore1.invoke(() -> initDataStore(createIndex, regionType));
dataStore2.invoke(() -> initDataStore(createIndex, regionType));
}
@@ -280,17 +281,17 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
public void creatingIndexAfterRegionAndStartingUpSecondMemberSucceeds(
RegionTestableType regionType) {
dataStore1.invoke(() -> {
+ cacheRule.createCache(getDistributedSystemProperties());
regionType.createDataStore(getCache(), REGION_NAME);
createIndexAfterRegion("field1");
});
dataStore2.invoke(() -> {
+ cacheRule.createCache(getDistributedSystemProperties());
createIndexAfterRegion("field1");
regionType.createDataStore(getCache(), REGION_NAME);
});
- dataStore1.invoke(() -> {
- putEntryAndQuery();
- });
+ dataStore1.invoke(this::putEntryAndQuery);
}
@Test()
@@ -298,40 +299,38 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
public void creatingIndexAfterRegionAndStartingUpSecondMemberWithoutIndexFails(
RegionTestableType regionType) {
dataStore1.invoke(() -> {
+ cacheRule.createCache(getDistributedSystemProperties());
regionType.createDataStore(getCache(), REGION_NAME);
createIndexAfterRegion("field1");
});
expectedException.expectCause(Matchers.instanceOf(IllegalStateException.class));
dataStore2.invoke(() -> {
+ cacheRule.createCache(getDistributedSystemProperties());
regionType.createDataStore(getCache(), REGION_NAME);
createIndexAfterRegion("field1");
});
- dataStore1.invoke(() -> {
- putEntryAndQuery();
- });
+ dataStore1.invoke(this::putEntryAndQuery);
}
@Test
@Parameters({"PARTITION", "PARTITION_REDUNDANT"})
public void creatingIndexAfterRegionInTwoMembersSucceed(RegionTestableType regionType)
- throws Exception {
+ throws InterruptedException {
dataStore1.invoke(() -> {
+ cacheRule.createCache(getDistributedSystemProperties());
regionType.createDataStore(getCache(), REGION_NAME);
});
dataStore2.invoke(() -> {
+ cacheRule.createCache(getDistributedSystemProperties());
regionType.createDataStore(getCache(), REGION_NAME);
});
- AsyncInvocation createIndex1 = dataStore1.invokeAsync(() -> {
- createIndexAfterRegion("field1");
- });
+ AsyncInvocation createIndex1 = dataStore1.invokeAsync(() -> createIndexAfterRegion("field1"));
- AsyncInvocation createIndex2 = dataStore2.invokeAsync(() -> {
- createIndexAfterRegion("field1");
- });
+ AsyncInvocation createIndex2 = dataStore2.invokeAsync(() -> createIndexAfterRegion("field1"));
createIndex1.join();
createIndex2.join();
@@ -339,9 +338,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
createIndex1.checkException();
createIndex2.checkException();
- dataStore1.invoke(() -> {
- putEntryAndQuery();
- });
+ dataStore1.invoke(this::putEntryAndQuery);
}
@Test
@@ -380,25 +377,19 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
}
protected Object[] getXmlAndExceptionMessages() {
- return $(
- new Object[] {"verifyDifferentFieldsFails", CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_FIELDS},
- new Object[] {"verifyDifferentFieldAnalyzerSizesFails1",
+ return new Object[]{
+ new Object[]{"verifyDifferentFieldsFails", CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_FIELDS},
+ new Object[]{"verifyDifferentFieldAnalyzerSizesFails1",
CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_FIELDS_2},
- new Object[] {"verifyDifferentFieldAnalyzerSizesFails2",
+ new Object[]{"verifyDifferentFieldAnalyzerSizesFails2",
CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_FIELDS},
- new Object[] {"verifyDifferentFieldAnalyzersFails1",
+ new Object[]{"verifyDifferentFieldAnalyzersFails1",
CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_ANALYZERS_2},
- // Currently setting a null analyzer is not a valid xml configuration: <lucene:field
- // name="field2" analyzer="null"/>
- // new Object[] { "verifyDifferentFieldAnalyzersFails2",
- // CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_ANALYZERS_1 },
- // new Object[] { "verifyDifferentFieldAnalyzersFails3",
- // CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_ANALYZERS_2 },
- new Object[] {"verifyDifferentIndexNamesFails", CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_NAMES},
- new Object[] {"verifyDifferentIndexesFails1",
+ new Object[]{"verifyDifferentIndexNamesFails", CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_NAMES},
+ new Object[]{"verifyDifferentIndexesFails1",
CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_INDEXES_1},
- new Object[] {"verifyDifferentIndexesFails2",
- CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_INDEXES_2});
+ new Object[]{"verifyDifferentIndexesFails2",
+ CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_INDEXES_2}};
}
@Test
@@ -421,6 +412,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
dataStore2.invoke(() -> initDataStore(createIndex2, regionType));
}
+ @Test
@Parameters("PARTITION")
public void verifyDifferentSerializerShouldFail(RegionTestableType regionType) {
SerializableRunnableIF createIndex1 = getIndexWithDefaultSerializer();
@@ -452,7 +444,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
// Attempt to create a Cache in dataStore2 with a PR defining 20 buckets. This will fail.
String exceptionMessage =
LocalizedStrings.PartitionedRegion_THE_TOTAL_NUMBER_OF_BUCKETS_FOUND_IN_PARTITIONATTRIBUTES_0_IS_INCOMPATIBLE_WITH_THE_TOTAL_NUMBER_OF_BUCKETS_USED_BY_OTHER_DISTRIBUTED_MEMBERS_SET_THE_NUMBER_OF_BUCKETS_TO_1
- .toLocalizedString(new Object[] {NUM_BUCKETS * 2, NUM_BUCKETS});
+ .toLocalizedString(NUM_BUCKETS * 2, NUM_BUCKETS);
dataStore2.invoke(() -> initDataStore(createIndex,
RegionTestableType.PARTITION_WITH_DOUBLE_BUCKETS, exceptionMessage));
@@ -469,7 +461,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
dataStore2.invoke(() -> verifyAsyncEventQueues(2));
}
- protected String getXmlFileForTest(String testName) {
+ private String getXmlFileForTest(String testName) {
return TestUtil.getResourcePath(getClass(),
getClassSimpleName() + "." + testName + ".cache.xml");
}
@@ -479,7 +471,8 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
}
protected void initDataStore(SerializableRunnableIF createIndex, RegionTestableType regionType,
- String message) throws Exception {
+ String message) throws Exception {
+ cacheRule.createCache();
createIndex.run();
try {
regionType.createDataStore(getCache(), REGION_NAME);
@@ -489,12 +482,14 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
}
}
- protected void initCache(String cacheXmlFileName) throws FileNotFoundException {
+ private void initCache(String cacheXmlFileName) throws FileNotFoundException {
+ cacheRule.createCache();
getCache().loadCacheXml(new FileInputStream(cacheXmlFileName));
}
- protected void initCache(String cacheXmlFileName, String message) throws FileNotFoundException {
+ private void initCache(String cacheXmlFileName, String message) throws FileNotFoundException {
try {
+ cacheRule.createCache();
getCache().loadCacheXml(new FileInputStream(cacheXmlFileName));
fail("Should not have been able to create cache");
} catch (IllegalStateException e) {
@@ -502,14 +497,14 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
}
}
- protected SerializableRunnableIF getFieldsIndexWithOneField() {
+ private SerializableRunnableIF getFieldsIndexWithOneField() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
luceneService.createIndexFactory().addField("field1").create(INDEX_NAME, REGION_NAME);
};
}
- protected SerializableRunnableIF getFieldsIndexWithTwoFields() {
+ private SerializableRunnableIF getFieldsIndexWithTwoFields() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
luceneService.createIndexFactory().addField("field1").addField("field2").create(INDEX_NAME,
@@ -517,7 +512,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
- protected SerializableRunnableIF get2FieldsIndexes() {
+ private SerializableRunnableIF get2FieldsIndexes() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
luceneService.createIndexFactory().addField("field1").create(INDEX_NAME + "_1", REGION_NAME);
@@ -525,7 +520,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
- protected SerializableRunnableIF getMultipleIndexes(final int numberOfIndexes) {
+ private SerializableRunnableIF getMultipleIndexes(final int numberOfIndexes) {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
for (int count = 1; count <= numberOfIndexes; count++) {
@@ -535,13 +530,13 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
- protected void verifyIndexList(final int expectedSize) {
+ private void verifyIndexList(final int expectedSize) {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
Collection<LuceneIndex> indexList = luceneService.getAllIndexes();
assertEquals(expectedSize, indexList.size());
}
- protected void verifyIndexes(final int numberOfIndexes) {
+ private void verifyIndexes(final int numberOfIndexes) {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
for (int count = 1; count <= numberOfIndexes; count++) {
assertEquals(INDEX_NAME + "_" + count,
@@ -549,7 +544,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
}
}
- protected SerializableRunnableIF getAnalyzersIndexWithNullField1() {
+ private SerializableRunnableIF getAnalyzersIndexWithNullField1() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
Map<String, Analyzer> analyzers = new HashMap<>();
@@ -559,7 +554,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
- protected SerializableRunnableIF getAnalyzersIndexWithNullField2() {
+ private SerializableRunnableIF getAnalyzersIndexWithNullField2() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
Map<String, Analyzer> analyzers = new HashMap<>();
@@ -569,7 +564,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
- protected SerializableRunnableIF getAnalyzersIndexWithOneField(
+ private SerializableRunnableIF getAnalyzersIndexWithOneField(
Class<? extends Analyzer> analyzerClass) {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
@@ -579,7 +574,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
- protected SerializableRunnableIF getAnalyzersIndexWithOneField() {
+ private SerializableRunnableIF getAnalyzersIndexWithOneField() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
Map<String, Analyzer> analyzers = new HashMap<>();
@@ -588,7 +583,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
- protected SerializableRunnableIF getAnalyzersIndexWithTwoFields() {
+ private SerializableRunnableIF getAnalyzersIndexWithTwoFields() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
Map<String, Analyzer> analyzers = new HashMap<>();
@@ -598,7 +593,7 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
- protected SerializableRunnableIF getAnalyzersIndexWithTwoFields2() {
+ private SerializableRunnableIF getAnalyzersIndexWithTwoFields2() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
Map<String, Analyzer> analyzers = new HashMap<>();
@@ -608,43 +603,42 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
- protected SerializableRunnableIF getIndexWithDummySerializer() {
+ private SerializableRunnableIF getIndexWithDummySerializer() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
- luceneService.createIndexFactory().setFields(new String[] {"field1", "field2"})
+ luceneService.createIndexFactory().setFields("field1", "field2")
.setLuceneSerializer(new DummyLuceneSerializer()).create(INDEX_NAME, REGION_NAME);
};
}
- protected SerializableRunnableIF getIndexWithDefaultSerializer() {
+ private SerializableRunnableIF getIndexWithDefaultSerializer() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
- luceneService.createIndexFactory().setFields(new String[] {"field1", "field2"})
- .create(INDEX_NAME, REGION_NAME);
+ luceneService.createIndexFactory().setFields("field1", "field2").create(INDEX_NAME,
+ REGION_NAME);
};
}
- protected SerializableRunnableIF getHeterogeneousLuceneSerializerCreationProfile() {
+ private SerializableRunnableIF getHeterogeneousLuceneSerializerCreationProfile() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
- luceneService.createIndexFactory().setFields(new String[] {"field1", "field2"})
+ luceneService.createIndexFactory().setFields("field1", "field2")
.setLuceneSerializer(new HeterogeneousLuceneSerializer()).create(INDEX_NAME, REGION_NAME);
};
}
- protected void initDataStore(RegionTestableType regionTestType) throws Exception {
+ protected void initDataStore(RegionTestableType regionTestType) {
regionTestType.createDataStore(getCache(), REGION_NAME);
}
- protected void verifyAsyncEventQueues(final int expectedSize) {
+ private void verifyAsyncEventQueues(final int expectedSize) {
assertEquals(expectedSize, getCache().getAsyncEventQueues(false).size());
}
private void createIndexAfterRegion(String... fields) {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
- LuceneIndexFactoryImpl indexFactory =
- (LuceneIndexFactoryImpl) luceneService.createIndexFactory();
- indexFactory.setFields(fields).create(INDEX_NAME, REGION_NAME, true);
+ ((LuceneIndexFactoryImpl) luceneService.createIndexFactory())
+ .setFields(fields).create(INDEX_NAME, REGION_NAME, true);
}
private void putEntryAndQuery() throws InterruptedException, LuceneQueryException {
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
index 83541a0..920b21c 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
@@ -30,6 +30,8 @@ import java.util.concurrent.TimeUnit;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.awaitility.Awaitility;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
@@ -49,6 +51,7 @@ import org.apache.geode.test.dunit.IgnoredException;
import org.apache.geode.test.dunit.SerializableRunnableIF;
import org.apache.geode.test.dunit.ThreadUtils;
import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.rules.DistributedDiskDirRule;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.categories.LuceneTest;
@@ -57,23 +60,26 @@ import org.apache.geode.test.junit.categories.LuceneTest;
public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
private static final String INDEX1_NAME = INDEX_NAME + "1";
-
private static final String INDEX2_NAME = INDEX_NAME + "2";
-
private static volatile boolean STOP_PUTS = false;
-
private static volatile boolean STOP_QUERIES = false;
-
private static int NUM_PUTS_COMPLETED = 0;
-
private static int NUM_QUERIES_COMPLETED = 0;
-
protected VM accessor;
- @Override
+ @Rule
+ public DistributedDiskDirRule distributedDiskDirRule = new DistributedDiskDirRule();
+
+ @Before
public void postSetUp() throws Exception {
- super.postSetUp();
- accessor = Host.getHost(0).getVM(3);
+ accessor = Host.getHost(0).getVM(2);
+ accessor.invoke(() -> cacheRule.createCache(getDistributedSystemProperties()));
+ }
+
+ protected void initAccessor(SerializableRunnableIF createIndex, RegionTestableType regionTestType)
+ throws Exception {
+ createIndex.run();
+ regionTestType.createAccessor(getCache(), REGION_NAME);
}
private Object[] parametersForIndexDestroys() {
@@ -90,8 +96,8 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
dataStore2.invoke(() -> initDataStore(createIndex(), regionType));
// Verify index created
- dataStore1.invoke(() -> verifyIndexCreated());
- dataStore2.invoke(() -> verifyIndexCreated());
+ dataStore1.invoke(this::verifyIndexCreated);
+ dataStore2.invoke(this::verifyIndexCreated);
// Attempt to destroy data region (should fail)
if (destroyDataRegion) {
@@ -99,11 +105,11 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
}
// Destroy index (only needs to be done on one member)
- dataStore1.invoke(() -> destroyIndex());
+ dataStore1.invoke(this::destroyIndex);
// Verify index destroyed
- dataStore1.invoke(() -> verifyIndexDestroyed());
- dataStore2.invoke(() -> verifyIndexDestroyed());
+ dataStore1.invoke((SerializableRunnableIF) this::verifyIndexDestroyed);
+ dataStore2.invoke((SerializableRunnableIF) this::verifyIndexDestroyed);
// Attempt to destroy data region (should succeed)
if (destroyDataRegion) {
@@ -119,8 +125,8 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
dataStore2.invoke(() -> initDataStore(createIndexes(), regionType));
// Verify indexes created
- dataStore1.invoke(() -> verifyIndexesCreated());
- dataStore2.invoke(() -> verifyIndexesCreated());
+ dataStore1.invoke(this::verifyIndexesCreated);
+ dataStore2.invoke(this::verifyIndexesCreated);
// Attempt to destroy data region (should fail)
if (destroyDataRegion) {
@@ -128,11 +134,11 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
}
// Destroy indexes (only needs to be done on one member)
- dataStore1.invoke(() -> destroyIndexes());
+ dataStore1.invoke(this::destroyIndexes);
// Verify indexes destroyed
- dataStore1.invoke(() -> verifyIndexesDestroyed());
- dataStore2.invoke(() -> verifyIndexesDestroyed());
+ dataStore1.invoke(this::verifyIndexesDestroyed);
+ dataStore2.invoke(this::verifyIndexesDestroyed);
// Attempt to destroy data region (should succeed)
if (destroyDataRegion) {
@@ -152,24 +158,24 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
dataStore2.invoke(() -> initDataStore(createIndex(), regionType));
// Verify index created
- dataStore1.invoke(() -> verifyIndexCreated());
- dataStore2.invoke(() -> verifyIndexCreated());
+ dataStore1.invoke(this::verifyIndexCreated);
+ dataStore2.invoke(this::verifyIndexCreated);
// Start puts
- AsyncInvocation putter = dataStore1.invokeAsync(() -> doPutsUntilStopped());
+ AsyncInvocation putter = dataStore1.invokeAsync(this::doPutsUntilStopped);
// Wait until puts have started
- dataStore1.invoke(() -> waitUntilPutsHaveStarted());
+ dataStore1.invoke(this::waitUntilPutsHaveStarted);
// Destroy index (only needs to be done on one member)
- dataStore1.invoke(() -> destroyIndex());
+ dataStore1.invoke(this::destroyIndex);
// Verify index destroyed
- dataStore1.invoke(() -> verifyIndexDestroyed());
- dataStore2.invoke(() -> verifyIndexDestroyed());
+ dataStore1.invoke((SerializableRunnableIF) this::verifyIndexDestroyed);
+ dataStore2.invoke((SerializableRunnableIF) this::verifyIndexDestroyed);
// End puts
- dataStore1.invoke(() -> stopPuts());
+ dataStore1.invoke(LuceneIndexDestroyDUnitTest::stopPuts);
// Wait for the putter to complete and verify no exception has occurred
ThreadUtils.join(putter, 60 * 1000);
@@ -178,7 +184,7 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
}
// Verify region size
- dataStore1.invoke(() -> verifyRegionSize());
+ dataStore1.invoke(this::verifyRegionSize);
}
@Test
@@ -193,24 +199,24 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
dataStore2.invoke(() -> initDataStore(createIndexes(), regionType));
// Verify indexes created
- dataStore1.invoke(() -> verifyIndexesCreated());
- dataStore2.invoke(() -> verifyIndexesCreated());
+ dataStore1.invoke(this::verifyIndexesCreated);
+ dataStore2.invoke(this::verifyIndexesCreated);
// Start puts
- AsyncInvocation putter = dataStore1.invokeAsync(() -> doPutsUntilStopped());
+ AsyncInvocation putter = dataStore1.invokeAsync(this::doPutsUntilStopped);
// Wait until puts have started
- dataStore1.invoke(() -> waitUntilPutsHaveStarted());
+ dataStore1.invoke(this::waitUntilPutsHaveStarted);
// Destroy indexes (only needs to be done on one member)
- dataStore1.invoke(() -> destroyIndexes());
+ dataStore1.invoke(this::destroyIndexes);
// Verify indexes destroyed
- dataStore1.invoke(() -> verifyIndexesDestroyed());
- dataStore2.invoke(() -> verifyIndexesDestroyed());
+ dataStore1.invoke(this::verifyIndexesDestroyed);
+ dataStore2.invoke(this::verifyIndexesDestroyed);
// End puts
- dataStore1.invoke(() -> stopPuts());
+ dataStore1.invoke(LuceneIndexDestroyDUnitTest::stopPuts);
// Wait for the putter to complete and verify no unexpected exception has occurred
ThreadUtils.join(putter, 60 * 1000);
@@ -219,7 +225,7 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
}
// Verify region size
- dataStore1.invoke(() -> verifyRegionSize());
+ dataStore1.invoke(this::verifyRegionSize);
}
@Test
@@ -233,9 +239,9 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
accessor.invoke(() -> initAccessor(createIndex, regionType));
// Verify index created
- dataStore1.invoke(() -> verifyIndexCreated());
- dataStore2.invoke(() -> verifyIndexCreated());
- accessor.invoke(() -> verifyIndexCreated());
+ dataStore1.invoke(this::verifyIndexCreated);
+ dataStore2.invoke(this::verifyIndexCreated);
+ accessor.invoke(this::verifyIndexCreated);
// Do puts
int numPuts = 100;
@@ -249,15 +255,15 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
.invokeAsync(() -> doQueriesUntilException(INDEX_NAME, "field1Value", "field1", numPuts));
// Wait until queries have started
- accessor.invoke(() -> waitUntilQueriesHaveStarted());
+ accessor.invoke(this::waitUntilQueriesHaveStarted);
// Destroy index (only needs to be done on one member)
- accessor.invoke(() -> destroyIndex());
+ accessor.invoke(this::destroyIndex);
// Verify index destroyed
- dataStore1.invoke(() -> verifyIndexDestroyed());
- dataStore2.invoke(() -> verifyIndexDestroyed());
- accessor.invoke(() -> verifyIndexDestroyed());
+ dataStore1.invoke((SerializableRunnableIF) this::verifyIndexDestroyed);
+ dataStore2.invoke((SerializableRunnableIF) this::verifyIndexDestroyed);
+ accessor.invoke((SerializableRunnableIF) this::verifyIndexDestroyed);
// Wait for the querier to complete and verify no exception has occurred
ThreadUtils.join(querier, 60 * 1000);
@@ -277,8 +283,8 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
accessor.invoke(() -> initAccessor(createIndexes, regionType));
// Verify indexes created
- dataStore1.invoke(() -> verifyIndexesCreated());
- dataStore2.invoke(() -> verifyIndexesCreated());
+ dataStore1.invoke(this::verifyIndexesCreated);
+ dataStore2.invoke(this::verifyIndexesCreated);
accessor.invoke(() -> verifyIndexesCreated());
// Do puts
@@ -430,9 +436,9 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
accessor.invoke(() -> initAccessor(createIndex, regionType));
// Verify index created
- dataStore1.invoke(() -> verifyIndexCreated());
- dataStore2.invoke(() -> verifyIndexCreated());
- accessor.invoke(() -> verifyIndexCreated());
+ dataStore1.invoke(this::verifyIndexCreated);
+ dataStore2.invoke(this::verifyIndexCreated);
+ accessor.invoke(this::verifyIndexCreated);
// Do puts to cause IndexRepositories to be created
int numPuts = 1000;
@@ -448,11 +454,11 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
accessor.invoke(() -> exportData(regionType));
// Destroy indexes (only needs to be done on one member)
- dataStore1.invoke(() -> destroyIndexes());
+ dataStore1.invoke(this::destroyIndexes);
// Verify indexes destroyed
- dataStore1.invoke(() -> verifyIndexesDestroyed());
- dataStore2.invoke(() -> verifyIndexesDestroyed());
+ dataStore1.invoke(this::verifyIndexesDestroyed);
+ dataStore2.invoke(this::verifyIndexesDestroyed);
// Destroy data region
dataStore1.invoke(() -> destroyDataRegion(true));
@@ -678,7 +684,7 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
private void exportData(RegionTestableType regionType) throws Exception {
Region region = getCache().getRegion(REGION_NAME);
RegionSnapshotService service = region.getSnapshotService();
- service.save(getSnapshotFile(getDiskDirs()[0], regionType),
+ service.save(getSnapshotFile(distributedDiskDirRule.getDiskDirFor(VM.getVM(0)), regionType),
SnapshotOptions.SnapshotFormat.GEMFIRE);
}
@@ -687,7 +693,7 @@ public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
RegionSnapshotService service = region.getSnapshotService();
SnapshotOptions options = service.createOptions();
options.invokeCallbacks(true);
- service.load(getSnapshotFile(getDiskDirs()[0], regionType),
+ service.load(getSnapshotFile(distributedDiskDirRule.getDiskDirFor(VM.getVM(0)), regionType),
SnapshotOptions.SnapshotFormat.GEMFIRE, options);
assertEquals(expectedRegionSize, region.size());
}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesAccessorBase.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesAccessorBase.java
index c7ac4a7..59d2a8f 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesAccessorBase.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesAccessorBase.java
@@ -33,8 +33,12 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
+import org.junit.Before;
+import org.junit.ClassRule;
+
import org.apache.geode.DataSerializable;
import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.control.RebalanceOperation;
import org.apache.geode.cache.control.RebalanceResults;
@@ -49,37 +53,48 @@ import org.apache.geode.internal.cache.PartitionedRegion;
import org.apache.geode.internal.cache.partitioned.BecomePrimaryBucketMessage;
import org.apache.geode.internal.cache.partitioned.BecomePrimaryBucketMessage.BecomePrimaryBucketResponse;
import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.rules.DistributedTestRule;
public class LuceneQueriesAccessorBase extends LuceneDUnitTest {
+ @ClassRule
+ public static DistributedTestRule distributedTestRule = new DistributedTestRule(3);
+
protected VM accessor;
- @Override
+ @Before
public void postSetUp() throws Exception {
- super.postSetUp();
- accessor = Host.getHost(0).getVM(3);
+ accessor = Host.getHost(0).getVM(2);
}
- protected void putDataInRegion(VM vm) {
- vm.invoke(() -> {
- final Cache cache = getCache();
- Region<Object, Object> region = cache.getRegion(REGION_NAME);
- region.put(1, new TestObject("hello world"));
- region.put(113, new TestObject("hi world"));
- region.put(2, new TestObject("goodbye world"));
- });
+ protected void initAccessor(SerializableRunnableIF createIndex, RegionTestableType regionTestType)
+ throws Exception {
+ createIndex.run();
+ regionTestType.createAccessor((Cache) getAccessorCache(), REGION_NAME);
}
- protected boolean waitForFlushBeforeExecuteTextSearch(VM vm, int ms) {
- return vm.invoke(() -> {
- Cache cache = getCache();
+ protected void putDataInRegion() {
+ final Cache cache = (Cache) getAccessorCache();
+ Region<Object, Object> region = cache.getRegion(REGION_NAME);
+ region.put(1, new TestObject("hello world"));
+ region.put(113, new TestObject("hi world"));
+ region.put(2, new TestObject("goodbye world"));
+ }
- LuceneService service = LuceneServiceProvider.get(cache);
- LuceneIndexImpl index = (LuceneIndexImpl) service.getIndex(INDEX_NAME, REGION_NAME);
+ protected boolean waitForFlushBeforeExecuteTextSearch(int timeoutInMillis)
+ throws InterruptedException {
+ return waitForFlushBeforeExecuteTextSearch(getCache(), timeoutInMillis);
+ }
- return service.waitUntilFlushed(INDEX_NAME, REGION_NAME, ms, TimeUnit.MILLISECONDS);
- });
+ protected boolean waitForFlushBeforeExecuteTextSearch(Cache cache, int timeoutInMillis)
+ throws InterruptedException {
+ LuceneService service = LuceneServiceProvider.get(cache);
+ LuceneIndexImpl index = (LuceneIndexImpl) service.getIndex(INDEX_NAME, REGION_NAME);
+
+ return service.waitUntilFlushed(INDEX_NAME, REGION_NAME, timeoutInMillis,
+ TimeUnit.MILLISECONDS);
}
protected void executeTextSearch(VM vm) {
@@ -130,7 +145,7 @@ public class LuceneQueriesAccessorBase extends LuceneDUnitTest {
query = service.createLuceneQueryFactory().setLimit(1000).setPageSize(1000).create(INDEX_NAME,
REGION_NAME, queryString, defaultField);
try {
- Collection<?> results = query.findKeys();
+ query.findKeys();
fail("Query " + defaultField + ":" + queryString + " should not have succeeded");
} catch (Exception e) {
assertEquals(expctedExceptionClass, e.getClass());
@@ -186,12 +201,10 @@ public class LuceneQueriesAccessorBase extends LuceneDUnitTest {
assertTrue(response.waitForResponse());
}
- protected void removeCallback(VM vm) {
- vm.invoke(() -> {
- IndexRepositorySpy.remove();
- InitialImageOperation.resetAllGIITestHooks();
- LuceneIndexFactorySpy.remove();
- });
+ protected void removeCallback() {
+ IndexRepositorySpy.remove();
+ InitialImageOperation.resetAllGIITestHooks();
+ LuceneIndexFactorySpy.remove();
}
protected void rebalanceRegion(VM vm) {
@@ -202,6 +215,10 @@ public class LuceneQueriesAccessorBase extends LuceneDUnitTest {
});
}
+ protected GemFireCache getAccessorCache() {
+ return cacheRule.getCache();
+ }
+
protected static class TestObject implements DataSerializable {
private static final long serialVersionUID = 1L;
private String text;
@@ -222,18 +239,23 @@ public class LuceneQueriesAccessorBase extends LuceneDUnitTest {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
TestObject other = (TestObject) obj;
if (text == null) {
- if (other.text != null)
+ if (other.text != null) {
return false;
- } else if (!text.equals(other.text))
+ }
+ } else if (!text.equals(other.text)) {
return false;
+ }
return true;
}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesClientDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesClientDUnitTest.java
index 6464471..cb0d490 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesClientDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesClientDUnitTest.java
@@ -17,16 +17,19 @@ package org.apache.geode.cache.lucene;
import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
import junitparams.JUnitParamsRunner;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.test.dunit.SerializableCallableIF;
import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.dunit.rules.ClientCacheRule;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.categories.LuceneTest;
@@ -34,11 +37,20 @@ import org.apache.geode.test.junit.categories.LuceneTest;
@RunWith(JUnitParamsRunner.class)
public class LuceneQueriesClientDUnitTest extends LuceneQueriesDUnitTest {
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
@Override
- public void postSetUp() throws Exception {
- super.postSetUp();
+ protected GemFireCache getAccessorCache() {
+ return clientCacheRule.getClientCache();
+ }
+
+ @Before
+ public void init() {
+ dataStore1.invoke(() -> cacheRule.createCache(getDistributedSystemProperties()));
+ dataStore2.invoke(() -> cacheRule.createCache(getDistributedSystemProperties()));
SerializableCallableIF<Integer> launchServer = () -> {
- final Cache cache = getCache();
+ final Cache cache = cacheRule.getCache();
final CacheServer server = cache.addCacheServer();
server.setPort(0);
server.start();
@@ -46,13 +58,13 @@ public class LuceneQueriesClientDUnitTest extends LuceneQueriesDUnitTest {
};
final int port1 = dataStore1.invoke(launchServer);
final int port2 = dataStore2.invoke(launchServer);
-
accessor.invoke(() -> {
ClientCacheFactory clientCacheFactory = new ClientCacheFactory();
clientCacheFactory.addPoolServer("localhost", port1);
clientCacheFactory.addPoolServer("localhost", port2);
- ClientCache clientCache = getClientCache(clientCacheFactory);
- clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(REGION_NAME);
+ clientCacheRule.createClientCache(clientCacheFactory);
+ clientCacheRule.getClientCache().createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
+ .create(REGION_NAME);
});
}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
index 42813b2..d4168c3 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
@@ -28,6 +28,7 @@ import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.TermQuery;
+import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
@@ -46,13 +47,15 @@ import org.apache.geode.test.junit.categories.LuceneTest;
/**
* This test class is intended to contain basic integration tests of the lucene query class that
* should be executed against a number of different regions types and topologies.
- *
*/
@Category({DistributedTest.class, LuceneTest.class})
@RunWith(JUnitParamsRunner.class)
public class LuceneQueriesDUnitTest extends LuceneQueriesAccessorBase {
- private static final long serialVersionUID = 1L;
+ @Before
+ public void init() {
+ accessor.invoke(() -> cacheRule.createCache(getDistributedSystemProperties()));
+ }
protected SerializableRunnable createIndex = new SerializableRunnable("createIndex") {
public void run() {
@@ -74,12 +77,13 @@ public class LuceneQueriesDUnitTest extends LuceneQueriesAccessorBase {
public void transactionWithLuceneQueriesShouldThrowException(RegionTestableType regionTestType)
throws Exception {
createRegionAndIndexForAllDataStores(regionTestType, createIndex);
- putDataInRegion(accessor);
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+ accessor.invoke(this::putDataInRegion);
+ assertTrue(accessor
+ .invoke(() -> waitForFlushBeforeExecuteTextSearch((Cache) getAccessorCache(), 60000)));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
accessor.invoke(() -> {
- Cache cache = getCache();
+ Cache cache = (Cache) getAccessorCache();
try {
LuceneService service = LuceneServiceProvider.get(cache);
LuceneQuery<Integer, TestObject> query;
@@ -104,9 +108,10 @@ public class LuceneQueriesDUnitTest extends LuceneQueriesAccessorBase {
public void returnCorrectResultsFromStringQueryWithDefaultAnalyzer(
RegionTestableType regionTestType) throws Exception {
createRegionAndIndexForAllDataStores(regionTestType, createIndex);
- putDataInRegion(accessor);
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+ accessor.invoke(this::putDataInRegion);
+ assertTrue(accessor
+ .invoke(() -> waitForFlushBeforeExecuteTextSearch((Cache) getAccessorCache(), 60000)));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearch(accessor);
}
@@ -115,9 +120,10 @@ public class LuceneQueriesDUnitTest extends LuceneQueriesAccessorBase {
public void defaultFieldShouldPropogateCorrectlyThroughFunction(RegionTestableType regionTestType)
throws Exception {
createRegionAndIndexForAllDataStores(regionTestType, createIndex);
- putDataInRegion(accessor);
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+ accessor.invoke(this::putDataInRegion);
+ assertTrue(accessor
+ .invoke(() -> waitForFlushBeforeExecuteTextSearch((Cache) getAccessorCache(), 60000)));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearch(accessor, "world", "text", 3);
executeTextSearch(accessor, "world", "noEntriesMapped", 0);
}
@@ -127,18 +133,17 @@ public class LuceneQueriesDUnitTest extends LuceneQueriesAccessorBase {
public void canQueryWithCustomLuceneQueryObject(RegionTestableType regionTestType)
throws Exception {
createRegionAndIndexForAllDataStores(regionTestType, createIndex);
- putDataInRegion(accessor);
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+ accessor.invoke(this::putDataInRegion);
+ assertTrue(accessor
+ .invoke(() -> waitForFlushBeforeExecuteTextSearch((Cache) getAccessorCache(), 60000)));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
// Execute a query with a custom lucene query object
accessor.invoke(() -> {
- Cache cache = getCache();
+ Cache cache = (Cache) getAccessorCache();
LuceneService service = LuceneServiceProvider.get(cache);
- LuceneQuery query =
- service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, index -> {
- return new TermQuery(new Term("text", "world"));
- });
+ LuceneQuery query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME,
+ index -> new TermQuery(new Term("text", "world")));
final PageableLuceneQueryResults results = query.findPages();
assertEquals(3, results.size());
});
@@ -151,11 +156,13 @@ public class LuceneQueriesDUnitTest extends LuceneQueriesAccessorBase {
createRegionAndIndexForAllDataStores(regionTestType, createIndex);
dataStore1.invoke(() -> LuceneTestUtilities.pauseSender(getCache()));
dataStore2.invoke(() -> LuceneTestUtilities.pauseSender(getCache()));
- putDataInRegion(accessor);
- assertFalse(waitForFlushBeforeExecuteTextSearch(accessor, 200));
+ accessor.invoke(this::putDataInRegion);
+ assertFalse(accessor
+ .invoke(() -> waitForFlushBeforeExecuteTextSearch((Cache) getAccessorCache(), 200)));
dataStore1.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
dataStore2.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
+ assertTrue(accessor
+ .invoke(() -> waitForFlushBeforeExecuteTextSearch((Cache) getAccessorCache(), 60000)));
executeTextSearch(accessor, "world", "text", 3);
executeTextSearch(accessor, "world", "noEntriesMapped", 0);
}
@@ -164,9 +171,10 @@ public class LuceneQueriesDUnitTest extends LuceneQueriesAccessorBase {
@Parameters(method = "getListOfRegionTestTypes")
public void verifyWildcardQueriesSucceed(RegionTestableType regionTestType) throws Exception {
createRegionAndIndexForAllDataStores(regionTestType, createIndex);
- putDataInRegion(accessor);
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+ accessor.invoke(this::putDataInRegion);
+ assertTrue(accessor
+ .invoke(() -> waitForFlushBeforeExecuteTextSearch((Cache) getAccessorCache(), 60000)));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearch(accessor, "*", "*", 3);
executeTextSearch(accessor, "*:*", "text", 3);
executeTextSearch(accessor, "*:*", "XXX", 3);
@@ -177,9 +185,10 @@ public class LuceneQueriesDUnitTest extends LuceneQueriesAccessorBase {
@Parameters(method = "getListOfRegionTestTypes")
public void verifySpaceQueriesFail(RegionTestableType regionTestType) throws Exception {
createRegionAndIndexForAllDataStores(regionTestType, createIndex);
- putDataInRegion(accessor);
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+ accessor.invoke(this::putDataInRegion);
+ assertTrue(accessor
+ .invoke(() -> waitForFlushBeforeExecuteTextSearch((Cache) getAccessorCache(), 60000)));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearchWithExpectedException(accessor, " ", "*", LuceneQueryException.class);
executeTextSearchWithExpectedException(accessor, " ", "text", LuceneQueryException.class);
executeTextSearchWithExpectedException(accessor, " ", "XXX", LuceneQueryException.class);
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexClientDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexClientDUnitTest.java
index 0986390..7dabb68 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexClientDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexClientDUnitTest.java
@@ -17,16 +17,17 @@ package org.apache.geode.cache.lucene;
import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
import junitparams.JUnitParamsRunner;
+import org.junit.Rule;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.test.dunit.SerializableCallableIF;
import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.dunit.rules.ClientCacheRule;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.categories.LuceneTest;
@@ -39,7 +40,8 @@ import org.apache.geode.test.junit.categories.LuceneTest;
@RunWith(JUnitParamsRunner.class)
public class LuceneQueriesReindexClientDUnitTest extends LuceneQueriesReindexDUnitTest {
- private static final long serialVersionUID = 1L;
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
@Override
public void postSetUp() throws Exception {
@@ -58,8 +60,10 @@ public class LuceneQueriesReindexClientDUnitTest extends LuceneQueriesReindexDUn
ClientCacheFactory clientCacheFactory = new ClientCacheFactory();
clientCacheFactory.addPoolServer("localhost", port1);
clientCacheFactory.addPoolServer("localhost", port2);
- ClientCache clientCache = getClientCache(clientCacheFactory);
- clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(REGION_NAME);
+
+ clientCacheRule.createClientCache(clientCacheFactory);
+ clientCacheRule.getClientCache().createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
+ .create(REGION_NAME);
});
}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexDUnitTest.java
index e25ca9a..e4f8e93 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexDUnitTest.java
@@ -39,8 +39,6 @@ import org.apache.geode.test.junit.categories.LuceneTest;
@RunWith(JUnitParamsRunner.class)
public class LuceneQueriesReindexDUnitTest extends LuceneQueriesAccessorBase {
- private static final long serialVersionUID = 1L;
-
private void destroyIndex() {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
luceneService.destroyIndex(INDEX_NAME, REGION_NAME);
@@ -51,7 +49,41 @@ public class LuceneQueriesReindexDUnitTest extends LuceneQueriesAccessorBase {
LuceneIndexFactoryImpl indexFactory =
(LuceneIndexFactoryImpl) luceneService.createIndexFactory().addField("text");
indexFactory.create(INDEX_NAME, REGION_NAME, true);
- };
+ }
+
+ @Test
+ @Parameters(method = "getListOfRegionTestTypes")
+ public void dropAndRecreateIndex2(RegionTestableType regionTestType) throws Exception {
+ dataStore1.invoke(() -> initDataStore(regionTestType));
+ dataStore2.invoke(() -> initDataStore(regionTestType));
+ accessor.invoke(() -> initAccessor(regionTestType));
+
+ accessor.invoke(this::putDataInRegion);
+
+ // re-index stored data
+ AsyncInvocation ai1 = dataStore1.invokeAsync(() -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ LuceneIndexFactoryImpl indexFactory =
+ (LuceneIndexFactoryImpl) luceneService.createIndexFactory().addField("text");
+ indexFactory.create(INDEX_NAME, REGION_NAME, true);
+ });
+
+ AsyncInvocation ai2 = dataStore2.invokeAsync(() -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ LuceneIndexFactoryImpl indexFactory =
+ (LuceneIndexFactoryImpl) luceneService.createIndexFactory().addField("text2");
+ indexFactory.create(INDEX_NAME, REGION_NAME, true);
+ });
+
+ ai1.join();
+ ai2.join();
+
+ ai1.checkException();
+ ai2.checkException();
+
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
+ executeTextSearch(accessor);
+ }
@Test
@Parameters(method = "getListOfRegionTestTypes")
@@ -64,21 +96,17 @@ public class LuceneQueriesReindexDUnitTest extends LuceneQueriesAccessorBase {
dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
accessor.invoke(() -> initAccessor(createIndex, regionTestType));
- putDataInRegion(accessor);
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+ accessor.invoke(this::putDataInRegion);
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearch(accessor);
- dataStore1.invoke(() -> destroyIndex());
+ dataStore1.invoke(this::destroyIndex);
// re-index stored data
- AsyncInvocation ai1 = dataStore1.invokeAsync(() -> {
- recreateIndex();
- });
+ AsyncInvocation ai1 = dataStore1.invokeAsync(this::recreateIndex);
- AsyncInvocation ai2 = dataStore2.invokeAsync(() -> {
- recreateIndex();
- });
+ AsyncInvocation ai2 = dataStore2.invokeAsync(this::recreateIndex);
ai1.join();
ai2.join();
@@ -86,45 +114,37 @@ public class LuceneQueriesReindexDUnitTest extends LuceneQueriesAccessorBase {
ai1.checkException();
ai2.checkException();
- waitForFlushBeforeExecuteTextSearch(accessor, 60000);
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearch(accessor);
}
@Test
@Parameters(method = "getListOfRegionTestTypes")
public void reindexThenQuery(RegionTestableType regionTestType) throws Exception {
- SerializableRunnableIF createIndex = () -> {
- LuceneService luceneService = LuceneServiceProvider.get(getCache());
- LuceneIndexFactoryImpl indexFactory =
- (LuceneIndexFactoryImpl) luceneService.createIndexFactory().addField("text");
- indexFactory.create(INDEX_NAME, REGION_NAME, true);
- };
-
// Create dataRegion prior to index
dataStore1.invoke(() -> initDataStore(regionTestType));
dataStore2.invoke(() -> initDataStore(regionTestType));
accessor.invoke(() -> initAccessor(regionTestType));
// populate region
- putDataInRegion(accessor);
+ accessor.invoke(this::putDataInRegion);
// re-index stored data
- AsyncInvocation ai1 = dataStore1.invokeAsync(() -> {
- recreateIndex();
- });
+ AsyncInvocation ai1 = dataStore1.invokeAsync(this::recreateIndex);
// re-index stored data
- AsyncInvocation ai2 = dataStore2.invokeAsync(() -> {
- recreateIndex();
- });
+ AsyncInvocation ai2 = dataStore2.invokeAsync(this::recreateIndex);
+
+ AsyncInvocation ai3 = accessor.invokeAsync(this::recreateIndex);
ai1.join();
ai2.join();
+ ai3.join();
ai1.checkException();
ai2.checkException();
- waitForFlushBeforeExecuteTextSearch(accessor, 60000);
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearch(accessor);
}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/MixedObjectIndexDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/MixedObjectIndexDUnitTest.java
index af16c21..9c12bd6 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/MixedObjectIndexDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/MixedObjectIndexDUnitTest.java
@@ -79,7 +79,7 @@ public class MixedObjectIndexDUnitTest extends LuceneQueriesAccessorBase {
.forEach(i -> region.put(i, new TestObjectWithSameFieldName("hello world 2")));
});
- waitForFlushBeforeExecuteTextSearch(accessor, 60000);
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
accessor.invoke(() -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
@@ -112,17 +112,10 @@ public class MixedObjectIndexDUnitTest extends LuceneQueriesAccessorBase {
accessor.invoke(() -> initDataStore(createIndexOnTextAndDataField, regionTestableType));
- accessor.invoke(() -> {
- Region region = getCache().getRegion(REGION_NAME);
- IntStream.range(0, NUM_BUCKETS).forEach(i -> region.put(i, new TestObject("hello world")));
- IntStream.range(NUM_BUCKETS, 2 * NUM_BUCKETS)
- .forEach(i -> region.put(i, new TestObjectWithSameFieldName("hello world")));
- IntStream.range(2 * NUM_BUCKETS, 3 * NUM_BUCKETS)
- .forEach(i -> region.put(i, new TestObjectWithNoCommonField("hello world")));
- });
+ accessor.invoke(this::insertDataIntoRegions);
- waitForFlushBeforeExecuteTextSearch(accessor, 60000);
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
accessor.invoke(() -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
@@ -140,6 +133,14 @@ public class MixedObjectIndexDUnitTest extends LuceneQueriesAccessorBase {
});
}
+ private void insertDataIntoRegions() {
+ Region region = getCache().getRegion(REGION_NAME);
+ IntStream.range(0, NUM_BUCKETS).forEach(i -> region.put(i, new TestObject("hello world")));
+ IntStream.range(NUM_BUCKETS, 2 * NUM_BUCKETS)
+ .forEach(i -> region.put(i, new TestObjectWithSameFieldName("hello world")));
+ IntStream.range(2 * NUM_BUCKETS, 3 * NUM_BUCKETS)
+ .forEach(i -> region.put(i, new TestObjectWithNoCommonField("hello world")));
+ }
@Test
@@ -154,16 +155,9 @@ public class MixedObjectIndexDUnitTest extends LuceneQueriesAccessorBase {
accessor.invoke(() -> initDataStore(createIndexOnTextField, regionTestableType));
- accessor.invoke(() -> {
- Region region = getCache().getRegion(REGION_NAME);
- IntStream.range(0, NUM_BUCKETS).forEach(i -> region.put(i, new TestObject("hello world")));
- IntStream.range(NUM_BUCKETS, 2 * NUM_BUCKETS)
- .forEach(i -> region.put(i, new TestObjectWithSameFieldName("hello world")));
- IntStream.range(2 * NUM_BUCKETS, 3 * NUM_BUCKETS)
- .forEach(i -> region.put(i, new TestObjectWithNoCommonField("hello world")));
- });
+ accessor.invoke(this::insertDataIntoRegions);
- waitForFlushBeforeExecuteTextSearch(accessor, 60000);
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
accessor.invoke(() -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
@@ -197,7 +191,7 @@ public class MixedObjectIndexDUnitTest extends LuceneQueriesAccessorBase {
new TestObjectSameFieldNameButDifferentDataTypeFloat(new Float(999.1f))));
});
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
accessor.invoke(() -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/PaginationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/PaginationDUnitTest.java
index 94850ae..9a4219a 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/PaginationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/PaginationDUnitTest.java
@@ -33,8 +33,12 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheTransactionManager;
import org.apache.geode.cache.PartitionedRegionStorageException;
import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.test.dunit.Assert;
import org.apache.geode.test.dunit.SerializableRunnableIF;
import org.apache.geode.test.junit.categories.DistributedTest;
@@ -43,8 +47,8 @@ import org.apache.geode.test.junit.categories.LuceneTest;
@Category({DistributedTest.class, LuceneTest.class})
@RunWith(JUnitParamsRunner.class)
public class PaginationDUnitTest extends LuceneQueriesAccessorBase {
- protected static final int PAGE_SIZE = 2;
- protected static final int FLUSH_WAIT_TIME_MS = 60000;
+ private static final int PAGE_SIZE = 2;
+ private static final int FLUSH_WAIT_TIME_MS = 60000;
@Override
protected RegionTestableType[] getListOfRegionTestTypes() {
@@ -68,13 +72,12 @@ public class PaginationDUnitTest extends LuceneQueriesAccessorBase {
luceneService.createIndexFactory().setFields("text").create(INDEX_NAME, REGION_NAME);
};
-
dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
accessor.invoke(() -> initAccessor(createIndex, regionTestType));
putEntryInEachBucket();
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, FLUSH_WAIT_TIME_MS));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(FLUSH_WAIT_TIME_MS)));
accessor.invoke(() -> {
Cache cache = getCache();
@@ -108,14 +111,13 @@ public class PaginationDUnitTest extends LuceneQueriesAccessorBase {
luceneService.createIndexFactory().setFields("text").create(INDEX_NAME, REGION_NAME);
};
-
dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
accessor.invoke(() -> initAccessor(createIndex, regionTestType));
putEntryInEachBucket();
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, FLUSH_WAIT_TIME_MS));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(FLUSH_WAIT_TIME_MS)));
accessor.invoke(() -> {
List<LuceneResultStruct<Integer, TestObject>> combinedResult = new ArrayList<>();
@@ -152,4 +154,38 @@ public class PaginationDUnitTest extends LuceneQueriesAccessorBase {
}
}
+ protected final void closeCache() {
+ // Workaround for the fact that some classes are now extending
+ // CacheTestCase but not using it properly.
+ InternalCache cache = getCache();
+ if (cache == null) {
+ cache = GemFireCacheImpl.getInstance();
+ }
+ try {
+ if (cache != null) {
+ try {
+ if (!cache.isClosed()) {
+ if (cache instanceof GemFireCacheImpl) {
+ CacheTransactionManager transactionManager =
+ ((GemFireCacheImpl) cache).getTxManager();
+ if (transactionManager != null) {
+ if (transactionManager.exists()) {
+ try {
+ transactionManager.rollback();
+ } catch (Exception ignore) {
+
+ }
+ }
+ }
+ }
+ cache.close();
+ }
+ } finally {
+ }
+ } // cache != null
+ } finally {
+ PoolManager.close(false);
+ }
+ }
+
}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceDUnitTest.java
index db71787..c231d16 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceDUnitTest.java
@@ -27,7 +27,6 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
-import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
import org.apache.geode.distributed.DistributedMember;
@@ -44,13 +43,12 @@ import org.apache.geode.test.junit.categories.LuceneTest;
@RunWith(JUnitParamsRunner.class)
public class RebalanceDUnitTest extends LuceneQueriesAccessorBase {
- protected static int NUM_BUCKETS = 10;
-
+ private static int NUM_BUCKETS = 10;
@After
public void cleanupRebalanceCallback() {
- removeCallback(dataStore1);
- removeCallback(dataStore2);
+ dataStore1.invoke(this::removeCallback);
+ dataStore2.invoke(this::removeCallback);
}
protected RegionTestableType[] getListOfRegionTestTypes() {
@@ -58,7 +56,6 @@ public class RebalanceDUnitTest extends LuceneQueriesAccessorBase {
RegionTestableType.PARTITION_OVERFLOW_TO_DISK};
}
-
@Test
@Parameters(method = "getListOfRegionTestTypes")
public void returnCorrectResultsWhenRebalanceHappensOnIndexUpdate(
@@ -119,8 +116,9 @@ public class RebalanceDUnitTest extends LuceneQueriesAccessorBase {
putEntryInEachBucket();
dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
rebalanceRegion(dataStore2);
@@ -145,8 +143,8 @@ public class RebalanceDUnitTest extends LuceneQueriesAccessorBase {
rebalanceRegion(dataStore2);
dataStore1.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
- assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+ assertTrue(accessor.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearch(accessor, "world", "text", NUM_BUCKETS);
}
@@ -165,7 +163,7 @@ public class RebalanceDUnitTest extends LuceneQueriesAccessorBase {
dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
dataStore1.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
// dataStore3.invoke(() -> initDataStore(create, regionType));
executeTextSearch(accessor, "world", "text", NUM_BUCKETS);
@@ -174,8 +172,7 @@ public class RebalanceDUnitTest extends LuceneQueriesAccessorBase {
// Duplicated for now, try to abstract this out...
protected void putEntryInEachBucket() {
accessor.invoke(() -> {
- final Cache cache = getCache();
- Region<Object, Object> region = cache.getRegion(REGION_NAME);
+ Region<Object, Object> region = getCache().getRegion(REGION_NAME);
IntStream.range(0, NUM_BUCKETS).forEach(i -> region.put(i, new TestObject("hello world")));
});
}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyDUnitTest.java
index 2b68f99..3b183df 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyDUnitTest.java
@@ -53,8 +53,8 @@ public class RebalanceWithRedundancyDUnitTest extends LuceneQueriesAccessorBase
@After
public void cleanupRebalanceCallback() {
- removeCallback(dataStore1);
- removeCallback(dataStore2);
+ dataStore1.invoke(this::removeCallback);
+ dataStore2.invoke(this::removeCallback);
}
@Override
@@ -92,14 +92,16 @@ public class RebalanceWithRedundancyDUnitTest extends LuceneQueriesAccessorBase
spy.beforeWriteIndexRepository(doAfterN(key -> getCache().close(), 2));
});
- final String expectedExceptions = CacheClosedException.class.getName();
- dataStore1.invoke(addExceptionTag1(expectedExceptions));
+ dataStore1.invoke(() -> {
+ getCache().getLogger().info("<ExpectedException action=add>"
+ + CacheClosedException.class.getName() + "</ExpectedException>");
+ });
putEntriesAndValidateResultsWithRedundancy(regionTestType);
// Wait until the cache is closed in datastore1
- dataStore1.invoke(
- () -> Awaitility.await().atMost(60, TimeUnit.SECONDS).until(basicGetCache()::isClosed));
+ dataStore1
+ .invoke(() -> Awaitility.await().atMost(60, TimeUnit.SECONDS).until(getCache()::isClosed));
}
@Test
@@ -108,15 +110,14 @@ public class RebalanceWithRedundancyDUnitTest extends LuceneQueriesAccessorBase
RegionTestableType regionTestType) throws InterruptedException {
final DistributedMember member2 =
dataStore2.invoke(() -> getCache().getDistributedSystem().getDistributedMember());
- dataStore1.invoke(() -> {
- IndexRegionSpy.beforeWrite(getCache(), doAfterN(key -> getCache().close(), 100));
- });
+ dataStore1.invoke(
+ () -> IndexRegionSpy.beforeWrite(getCache(), doAfterN(key -> getCache().close(), 100)));
putEntriesAndValidateResultsWithRedundancy(regionTestType);
// Wait until the cache is closed in datastore1
- dataStore1.invoke(
- () -> Awaitility.await().atMost(60, TimeUnit.SECONDS).until(basicGetCache()::isClosed));
+ dataStore1
+ .invoke(() -> Awaitility.await().atMost(60, TimeUnit.SECONDS).until(getCache()::isClosed));
}
@Test
@@ -150,23 +151,22 @@ public class RebalanceWithRedundancyDUnitTest extends LuceneQueriesAccessorBase
@Override
public void run() {
dataStore1.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
- waitForFlushBeforeExecuteTextSearch(dataStore1, 30000);
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(30000)));
((TestResourceObserver) InternalResourceManager.getResourceObserver())
.recoveryFinished();
}
});
});
-
dataStore2.invoke(() -> {
initDataStore(createIndex, regionTestType);
((TestResourceObserver) InternalResourceManager.getResourceObserver()).await();
});
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 30000));
+ assertTrue(dataStore1.invoke(() -> waitForFlushBeforeExecuteTextSearch(30000)));
dataStore1.invoke(() -> getCache().close());
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore2, 30000));
+ assertTrue(dataStore2.invoke(() -> waitForFlushBeforeExecuteTextSearch(30000)));
executeTextSearch(accessor, "world", "text", NUM_BUCKETS);
}
@@ -186,11 +186,11 @@ public class RebalanceWithRedundancyDUnitTest extends LuceneQueriesAccessorBase
putEntryInEachBucket();
- dataStore1.invoke(() -> LuceneTestUtilities.resumeSender(basicGetCache()));
- dataStore2.invoke(() -> LuceneTestUtilities.resumeSender(basicGetCache()));
- accessor.invoke(() -> LuceneTestUtilities.resumeSender(basicGetCache()));
+ dataStore1.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
+ dataStore2.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
+ accessor.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
- assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore2, 60000));
+ assertTrue(dataStore2.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearch(accessor, "world", "text", NUM_BUCKETS);
}
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest.java
index 7b1f361..a599373 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest.java
@@ -26,6 +26,7 @@ import junitparams.Parameters;
import org.apache.logging.log4j.Logger;
import org.awaitility.Awaitility;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -58,11 +59,11 @@ public class RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest
private static final Logger logger = LogService.getLogger();
- protected VM dataStore3;
- protected VM dataStore4;
+ private VM dataStore3;
+ private VM dataStore4;
+ @After
public void postSetUp() throws Exception {
- super.postSetUp();
dataStore3 = Host.getHost(0).getVM(2);
dataStore4 = Host.getHost(0).getVM(3);
}
@@ -113,7 +114,7 @@ public class RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest
RebalanceResults rebalanceResults = null;
RebalanceOperation rebalanceOp = factory.start();
rebalanceResults = rebalanceOp.getResults();
- Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> rebalanceOp.isDone());
+ Awaitility.await().atMost(60, TimeUnit.SECONDS).until(rebalanceOp::isDone);
logger.info("Rebalance completed: "
+ RebalanceResultsToString(rebalanceResults, "Rebalance completed"));
}
@@ -170,7 +171,7 @@ public class RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest
createIndexAndRebalance(regionTestType, createIndex, true);
- waitForFlushBeforeExecuteTextSearch(dataStore3, 60000);
+ Assert.assertTrue(dataStore3.invoke(() -> waitForFlushBeforeExecuteTextSearch(60000)));
executeTextSearch(dataStore3, "world", "text", NUM_BUCKETS);
}
@@ -196,40 +197,36 @@ public class RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest
if (results == null) {
return "null";
}
- StringBuffer aStr = new StringBuffer();
- aStr.append("Rebalance results (" + title + ") totalTime: "
- + valueToString(results.getTotalTime()) + "\n");
+ StringBuilder aStr = new StringBuilder();
+ aStr.append("Rebalance results (").append(title).append(") totalTime: ")
+ .append(results.getTotalTime()).append("\n");
// bucketCreates
- aStr.append(
- "totalBucketCreatesCompleted: " + valueToString(results.getTotalBucketCreatesCompleted()));
- aStr.append(" totalBucketCreateBytes: " + valueToString(results.getTotalBucketCreateBytes()));
- aStr.append(
- " totalBucketCreateTime: " + valueToString(results.getTotalBucketCreateTime()) + "\n");
+ aStr.append("totalBucketCreatesCompleted: ").append(results.getTotalBucketCreatesCompleted());
+ aStr.append(" totalBucketCreateBytes: ").append(results.getTotalBucketCreateBytes());
+ aStr.append(" totalBucketCreateTime: ").append(results.getTotalBucketCreateTime()).append("\n");
// bucketTransfers
- aStr.append("totalBucketTransfersCompleted: "
- + valueToString(results.getTotalBucketTransfersCompleted()));
- aStr.append(
- " totalBucketTransferBytes: " + valueToString(results.getTotalBucketTransferBytes()));
- aStr.append(
- " totalBucketTransferTime: " + valueToString(results.getTotalBucketTransferTime()) + "\n");
+ aStr.append("totalBucketTransfersCompleted: ")
+ .append(results.getTotalBucketTransfersCompleted());
+ aStr.append(" totalBucketTransferBytes: ").append(results.getTotalBucketTransferBytes());
+ aStr.append(" totalBucketTransferTime: ").append(results.getTotalBucketTransferTime())
+ .append("\n");
// primaryTransfers
- aStr.append("totalPrimaryTransfersCompleted: "
- + valueToString(results.getTotalPrimaryTransfersCompleted()));
- aStr.append(" totalPrimaryTransferTime: " + valueToString(results.getTotalPrimaryTransferTime())
- + "\n");
+ aStr.append("totalPrimaryTransfersCompleted: ")
+ .append(results.getTotalPrimaryTransfersCompleted());
+ aStr.append(" totalPrimaryTransferTime: ").append(results.getTotalPrimaryTransferTime())
+ .append("\n");
// PartitionRebalanceDetails (per region)
Set<PartitionRebalanceInfo> prdSet = results.getPartitionRebalanceDetails();
for (PartitionRebalanceInfo prd : prdSet) {
aStr.append(partitionRebalanceDetailsToString(prd));
}
- aStr.append("total time (ms): " + valueToString(results.getTotalTime()));
+ aStr.append("total time (ms): ").append(results.getTotalTime());
- String returnStr = aStr.toString();
- return returnStr;
+ return aStr.toString();
}
private static String partitionRebalanceDetailsToString(PartitionRebalanceInfo details) {
@@ -237,25 +234,23 @@ public class RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest
return "null\n";
}
- StringBuffer aStr = new StringBuffer();
- aStr.append("PartitionedRegionDetails for region named " + getRegionName(details) + " time: "
- + valueToString(details.getTime()) + "\n");
+ StringBuilder aStr = new StringBuilder();
+ aStr.append("PartitionedRegionDetails for region named ").append(getRegionName(details))
+ .append(" time: ").append(details.getTime()).append("\n");
// bucketCreates
- aStr.append("bucketCreatesCompleted: " + valueToString(details.getBucketCreatesCompleted()));
- aStr.append(" bucketCreateBytes: " + valueToString(details.getBucketCreateBytes()));
- aStr.append(" bucketCreateTime: " + valueToString(details.getBucketCreateTime()) + "\n");
+ aStr.append("bucketCreatesCompleted: ").append(details.getBucketCreatesCompleted());
+ aStr.append(" bucketCreateBytes: ").append(details.getBucketCreateBytes());
+ aStr.append(" bucketCreateTime: ").append(details.getBucketCreateTime()).append("\n");
// bucketTransfers
- aStr.append(
- "bucketTransfersCompleted: " + valueToString(details.getBucketTransfersCompleted()));
- aStr.append(" bucketTransferBytes: " + valueToString(details.getBucketTransferBytes()));
- aStr.append(" bucketTransferTime: " + valueToString(details.getBucketTransferTime()) + "\n");
+ aStr.append("bucketTransfersCompleted: ").append(details.getBucketTransfersCompleted());
+ aStr.append(" bucketTransferBytes: ").append(details.getBucketTransferBytes());
+ aStr.append(" bucketTransferTime: ").append(details.getBucketTransferTime()).append("\n");
// primaryTransfers
- aStr.append(
- "PrimaryTransfersCompleted: " + valueToString(details.getPrimaryTransfersCompleted()));
- aStr.append(" PrimaryTransferTime: " + valueToString(details.getPrimaryTransferTime()) + "\n");
+ aStr.append("PrimaryTransfersCompleted: ").append(details.getPrimaryTransfersCompleted());
+ aStr.append(" PrimaryTransferTime: ").append(details.getPrimaryTransferTime()).append("\n");
// PartitionMemberDetails (before)
aStr.append("PartitionedMemberDetails (before)\n");
@@ -274,66 +269,20 @@ public class RebalanceWithRedundancyWithRegionCreatedBeforeReindexDUnitTest
return aStr.toString();
}
- public static String partitionedRegionDetailsToString(PartitionRegionInfo prd) {
-
- if (prd == null) {
- return "null\n";
- }
-
- StringBuffer aStr = new StringBuffer();
-
- aStr.append("PartitionedRegionDetails for region named " + getRegionName(prd) + "\n");
- aStr.append(" configuredBucketCount: " + valueToString(prd.getConfiguredBucketCount()) + "\n");
- aStr.append(" createdBucketCount: " + valueToString(prd.getCreatedBucketCount()) + "\n");
- aStr.append(
- " lowRedundancyBucketCount: " + valueToString(prd.getLowRedundancyBucketCount()) + "\n");
- aStr.append(
- " configuredRedundantCopies: " + valueToString(prd.getConfiguredRedundantCopies()) + "\n");
- aStr.append(" actualRedundantCopies: " + valueToString(prd.getActualRedundantCopies()) + "\n");
-
- // memberDetails
- Set<PartitionMemberInfo> pmd = prd.getPartitionMemberInfo();
- for (PartitionMemberInfo memberDetails : pmd) {
- aStr.append(partitionMemberDetailsToString(memberDetails));
- }
-
- // colocatedWithDetails
- String colocatedWith = prd.getColocatedWith();
- aStr.append(" colocatedWith: " + colocatedWith + "\n");
-
- String returnStr = aStr.toString();
- return returnStr;
- }
-
private static String partitionMemberDetailsToString(PartitionMemberInfo pmd) {
- StringBuffer aStr = new StringBuffer();
+ StringBuilder aStr = new StringBuilder();
long localMaxMemory = pmd.getConfiguredMaxMemory();
long size = pmd.getSize();
- aStr.append(" Member Details for: " + pmd.getDistributedMember() + "\n");
- aStr.append(" configuredMaxMemory: " + valueToString(localMaxMemory));
+ aStr.append(" Member Details for: ").append(pmd.getDistributedMember()).append("\n");
+ aStr.append(" configuredMaxMemory: ").append(localMaxMemory);
double inUse = (double) size / localMaxMemory;
double heapUtilization = inUse * 100;
- aStr.append(" size: " + size + " (" + valueToString(heapUtilization) + "%)");
- aStr.append(" bucketCount: " + valueToString(pmd.getBucketCount()));
- aStr.append(" primaryCount: " + valueToString(pmd.getPrimaryCount()) + "\n");
+ aStr.append(" size: ").append(size).append(" (").append(heapUtilization).append("%)");
+ aStr.append(" bucketCount: ").append(pmd.getBucketCount());
+ aStr.append(" primaryCount: ").append(pmd.getPrimaryCount()).append("\n");
return aStr.toString();
}
- /**
- * Convert the given long to a String; if it is negative then flag it in the string
- */
- private static String valueToString(long value) {
- String returnStr = "" + value;
- return returnStr;
- }
-
- /**
- * Convert the given double to a String; if it is negative then flag it in the string
- */
- private static String valueToString(double value) {
- String returnStr = "" + value;
- return returnStr;
- }
public static String getRegionName(PartitionRegionInfo prd) {
return prd.getRegionPath().substring(1);
--
To stop receiving notification emails like this one, please contact
udo@apache.org.