Skip to content

Commit 30428f7

Browse files
committed
Refactor asDirectoryName(:Class<?>) to qualify type based on declaring types and include a UUID in the pathname.
1 parent 6b5e7d5 commit 30428f7

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Map;
3131
import java.util.Objects;
3232
import java.util.Optional;
33+
import java.util.UUID;
3334
import java.util.WeakHashMap;
3435
import java.util.concurrent.TimeUnit;
3536
import java.util.concurrent.atomic.AtomicBoolean;
@@ -114,7 +115,7 @@ public abstract class IntegrationTestsSupport {
114115
protected static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(30);
115116
protected static final long DEFAULT_WAIT_INTERVAL = 500L; // milliseconds
116117

117-
protected static final String DATE_TIME_PATTERN = "yyyy-MM-dd-hh-mm-ss";
118+
protected static final String DATE_TIME_PATTERN = "yyyy-MM-dd-HH-mm-ss";
118119
protected static final String DIRECTORY_DELETE_ON_EXIT_PROPERTY = "spring.data.gemfire.test.directory.delete-on-exit";
119120
protected static final String DIRECTORY_NAME_FORMAT = "%1$s-%2$s";
120121
protected static final String GEMFIRE_LOG_FILE = "gemfire-server.log";
@@ -511,8 +512,25 @@ public static void stopGemFireLocatorWaitOnStopEvent(long duration) {
511512
}
512513

513514
protected static @NonNull String asDirectoryName(@NonNull Class<?> type) {
514-
return String.format(DIRECTORY_NAME_FORMAT, asApplicationName(type),
515+
516+
String baseDirectoryName = String.format(DIRECTORY_NAME_FORMAT, asQualifiedDirectoryName(type),
515517
LocalDateTime.now().format(DateTimeFormatter.ofPattern(DATE_TIME_PATTERN)));
518+
519+
return baseDirectoryName.concat(File.separator).concat(UUID.randomUUID().toString());
520+
}
521+
522+
private static @NonNull String asQualifiedDirectoryName(@NonNull Class<?> type) {
523+
524+
String qualifiedDirectoryName = asApplicationName(type);
525+
526+
Class<?> declaringType = type.getDeclaringClass();
527+
528+
while (declaringType != null) {
529+
qualifiedDirectoryName = asApplicationName(declaringType).concat(".").concat(qualifiedDirectoryName);
530+
declaringType = declaringType.getDeclaringClass();
531+
}
532+
533+
return qualifiedDirectoryName;
516534
}
517535

518536
protected static @NonNull File createDirectory(@NonNull String pathname) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2017-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
* or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
package org.springframework.data.gemfire.tests.integration;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import java.io.File;
21+
import java.time.LocalDateTime;
22+
import java.time.format.DateTimeFormatter;
23+
24+
import org.junit.Test;
25+
26+
/**
27+
* Unit Tests for {@link IntegrationTestsSupport}.
28+
*
29+
* @author John Blum
30+
* @see org.junit.Test
31+
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
32+
* @since 1.0.0
33+
*/
34+
public class IntegrationTestsSupportUnitTests {
35+
36+
@Test
37+
public void asDirectoryNameIsCorrect() {
38+
39+
LocalDateTime now = LocalDateTime.now();
40+
41+
String directoryName = IntegrationTestsSupport.asDirectoryName(OuterType.InnerType.class);
42+
43+
assertThat(directoryName).isNotBlank();
44+
assertThat(directoryName).startsWith(String.format("%s.%s.%s-%s%s",
45+
IntegrationTestsSupportUnitTests.class.getSimpleName(), OuterType.class.getSimpleName(), OuterType.InnerType.class.getSimpleName(),
46+
DateTimeFormatter.ofPattern(IntegrationTestsSupport.DATE_TIME_PATTERN).format(now),
47+
File.separator));
48+
49+
}
50+
51+
interface OuterType {
52+
interface InnerType { }
53+
}
54+
}

0 commit comments

Comments
 (0)