Skip to content

Commit 7c6869e

Browse files
committed
Fix CPD
1 parent 3a5e87a commit 7c6869e

File tree

10 files changed

+174
-341
lines changed

10 files changed

+174
-341
lines changed

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
</rulesets>
8585
<excludes>
8686
<exclude>**/benchmark/**/jmh_generated/**</exclude>
87+
<!-- Dynamic types for tests -->
88+
<exclude>**/shared/**/Customer*</exclude>
89+
<exclude>**/shared/**/Child*</exclude>
8790
</excludes>
8891
</configuration>
8992
<dependencies>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package software.xdev.spring.data.eclipse.store.benchmark.benchmarks.simple.customer;
2+
3+
import org.openjdk.jmh.annotations.Benchmark;
4+
5+
import software.xdev.spring.data.eclipse.store.benchmark.SpringState;
6+
7+
8+
@SuppressWarnings("checkstyle:MagicNumber")
9+
public abstract class AbstractStoringSimpleCustomerBenchmark
10+
{
11+
protected abstract void saveCustomerInForEach(final SpringState state, final int entityCount);
12+
13+
protected abstract void saveCustomerInSaveAll(final SpringState state, final int entityCount);
14+
15+
@Benchmark
16+
public void save100CustomerInForEach(final SpringState state)
17+
{
18+
this.saveCustomerInForEach(state, 100);
19+
}
20+
21+
@Benchmark
22+
public void save1000CustomerInForEach(final SpringState state)
23+
{
24+
this.saveCustomerInForEach(state, 1_000);
25+
}
26+
27+
@Benchmark
28+
public void save100CustomerInSaveAll(final SpringState state)
29+
{
30+
this.saveCustomerInSaveAll(state, 100);
31+
}
32+
33+
@Benchmark
34+
public void save1000CustomerInSaveAll(final SpringState state)
35+
{
36+
this.saveCustomerInSaveAll(state, 1_000);
37+
}
38+
39+
@Benchmark
40+
public void save10000CustomerInSaveAll(final SpringState state)
41+
{
42+
this.saveCustomerInSaveAll(state, 10_000);
43+
}
44+
45+
@Benchmark
46+
public void save100000CustomerInSaveAll(final SpringState state)
47+
{
48+
this.saveCustomerInSaveAll(state, 100_000);
49+
}
50+
}

spring-data-eclipse-store-benchmark/src/main/java/software/xdev/spring/data/eclipse/store/benchmark/benchmarks/simple/customer/StoringAndChangingSimpleCustomerBenchmark.java

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
99

1010

11-
@SuppressWarnings("checkstyle:MagicNumber")
12-
public class StoringAndChangingSimpleCustomerBenchmark
11+
public class StoringAndChangingSimpleCustomerBenchmark extends AbstractStoringSimpleCustomerBenchmark
1312
{
1413
@Benchmark
1514
public void saveSingleCustomer(final SpringState state)
@@ -29,43 +28,8 @@ public void saveSingleCustomer(final SpringState state)
2928
});
3029
}
3130

32-
@Benchmark
33-
public void save100CustomerInForEach(final SpringState state)
34-
{
35-
this.saveCustomerInForEach(state, 100);
36-
}
37-
38-
@Benchmark
39-
public void save100CustomerInSaveAll(final SpringState state)
40-
{
41-
this.saveCustomerInSaveAll(state, 100);
42-
}
43-
44-
@Benchmark
45-
public void save1000CustomerInSaveAll(final SpringState state)
46-
{
47-
this.saveCustomerInSaveAll(state, 1_000);
48-
}
49-
50-
@Benchmark
51-
public void save10000CustomerInSaveAll(final SpringState state)
52-
{
53-
this.saveCustomerInSaveAll(state, 10_000);
54-
}
55-
56-
@Benchmark
57-
public void save1000CustomerInForEach(final SpringState state)
58-
{
59-
this.saveCustomerInForEach(state, 1_000);
60-
}
61-
62-
@Benchmark
63-
public void save100000CustomerInSaveAll(final SpringState state)
64-
{
65-
this.saveCustomerInSaveAll(state, 100_000);
66-
}
67-
68-
private void saveCustomerInForEach(final SpringState state, final int entityCount)
31+
@Override
32+
protected void saveCustomerInForEach(final SpringState state, final int entityCount)
6933
{
7034
final CustomerRepository customerRepository1 = state.getBean(CustomerRepository.class);
7135
IntStream.range(0, entityCount).forEach(
@@ -84,7 +48,8 @@ private void saveCustomerInForEach(final SpringState state, final int entityCoun
8448
});
8549
}
8650

87-
private void saveCustomerInSaveAll(final SpringState state, final int entityCount)
51+
@Override
52+
protected void saveCustomerInSaveAll(final SpringState state, final int entityCount)
8853
{
8954
final CustomerRepository customerRepository = state.getBean(CustomerRepository.class);
9055
customerRepository.saveAll(

spring-data-eclipse-store-benchmark/src/main/java/software/xdev/spring/data/eclipse/store/benchmark/benchmarks/simple/customer/StoringSimpleCustomerBenchmark.java

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
@SuppressWarnings("checkstyle:MagicNumber")
11-
public class StoringSimpleCustomerBenchmark
11+
public class StoringSimpleCustomerBenchmark extends AbstractStoringSimpleCustomerBenchmark
1212
{
1313
@Benchmark
1414
public void saveSingleCustomer(final SpringState state)
@@ -17,36 +17,6 @@ public void saveSingleCustomer(final SpringState state)
1717
customerRepository.save(new Customer("Test", "Test"));
1818
}
1919

20-
@Benchmark
21-
public void save100CustomerInForEach(final SpringState state)
22-
{
23-
this.saveCustomerInForEach(state, 100);
24-
}
25-
26-
@Benchmark
27-
public void save100CustomerInSaveAll(final SpringState state)
28-
{
29-
this.saveCustomerInSaveAll(state, 100);
30-
}
31-
32-
@Benchmark
33-
public void save1000CustomerInSaveAll(final SpringState state)
34-
{
35-
this.saveCustomerInSaveAll(state, 1_000);
36-
}
37-
38-
@Benchmark
39-
public void save10000CustomerInSaveAll(final SpringState state)
40-
{
41-
this.saveCustomerInSaveAll(state, 10_000);
42-
}
43-
44-
@Benchmark
45-
public void save1000CustomerInForEach(final SpringState state)
46-
{
47-
this.saveCustomerInForEach(state, 1_000);
48-
}
49-
5020
@Benchmark
5121
public void save10000CustomerInForEach(final SpringState state)
5222
{
@@ -59,13 +29,8 @@ public void save10000CustomerInForEachParallel(final SpringState state)
5929
this.saveCustomerInForEachParallel(state, 10_000);
6030
}
6131

62-
@Benchmark
63-
public void save100000CustomerInSaveAll(final SpringState state)
64-
{
65-
this.saveCustomerInSaveAll(state, 100_000);
66-
}
67-
68-
private void saveCustomerInForEach(final SpringState state, final int entityCount)
32+
@Override
33+
protected void saveCustomerInForEach(final SpringState state, final int entityCount)
6934
{
7035
final CustomerRepository customerRepository = state.getBean(CustomerRepository.class);
7136
IntStream.range(0, entityCount).forEach(
@@ -81,7 +46,8 @@ private void saveCustomerInForEachParallel(final SpringState state, final int en
8146
);
8247
}
8348

84-
private void saveCustomerInSaveAll(final SpringState state, final int entityCount)
49+
@Override
50+
protected void saveCustomerInSaveAll(final SpringState state, final int entityCount)
8551
{
8652
final CustomerRepository customerRepository = state.getBean(CustomerRepository.class);
8753
customerRepository.saveAll(

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/LazyTest.java

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,8 @@ void lazyWorkingCopyChangeAfterRestart(@Autowired final ObjectWithLazyRepository
188188
@Test
189189
void lazyStoreComplexObject(@Autowired final ObjectWithLazyRepository<ComplexLazyObject> repository)
190190
{
191-
final ObjectWithLazy<ComplexLazyObject> newLazy = new ObjectWithLazy<>();
192-
final ComplexLazyObject objectToStore = new ComplexLazyObject(
193-
SpringDataEclipseStoreLazy.build(new SimpleObject(TestData.DUMMY_STRING)),
194-
new ArrayList<>(Arrays.asList(
195-
SpringDataEclipseStoreLazy.build(new ArrayList<>(Arrays.asList(TestData.DUMMY_STRING))),
196-
SpringDataEclipseStoreLazy.build(new ArrayList<>(Arrays.asList(TestData.DUMMY_STRING_ALTERNATIVE)))
197-
))
198-
);
199-
newLazy.setLazy(SpringDataEclipseStoreLazy.build(objectToStore));
200-
repository.save(newLazy);
191+
final ComplexLazyObject objectToStore =
192+
prepareLazyComplexObject(repository);
201193

202194
TestUtil.doBeforeAndAfterRestartOfDatastore(
203195
this.configuration,
@@ -222,16 +214,7 @@ void lazyStoreComplexObject(@Autowired final ObjectWithLazyRepository<ComplexLaz
222214
@Test
223215
void lazyChangeComplexObject(@Autowired final ObjectWithLazyRepository<ComplexLazyObject> repository)
224216
{
225-
final ObjectWithLazy<ComplexLazyObject> newLazy = new ObjectWithLazy<>();
226-
final ComplexLazyObject objectToStore = new ComplexLazyObject(
227-
SpringDataEclipseStoreLazy.build(new SimpleObject(TestData.DUMMY_STRING)),
228-
new ArrayList<>(Arrays.asList(
229-
SpringDataEclipseStoreLazy.build(new ArrayList<>(Arrays.asList(TestData.DUMMY_STRING))),
230-
SpringDataEclipseStoreLazy.build(new ArrayList<>(Arrays.asList(TestData.DUMMY_STRING_ALTERNATIVE)))
231-
))
232-
);
233-
newLazy.setLazy(SpringDataEclipseStoreLazy.build(objectToStore));
234-
repository.save(newLazy);
217+
prepareLazyComplexObject(repository);
235218

236219
restartDatastore(this.configuration);
237220

@@ -243,50 +226,43 @@ void lazyChangeComplexObject(@Autowired final ObjectWithLazyRepository<ComplexLa
243226
.add(SpringDataEclipseStoreLazy.build(List.of(TestData.DUMMY_STRING_ALTERNATIVE)));
244227
repository.save(loadedObjectToChange);
245228

246-
TestUtil.doBeforeAndAfterRestartOfDatastore(
247-
this.configuration,
248-
() -> {
249-
final ObjectWithLazy<ComplexLazyObject> loadedObject = repository.findAll().get(0);
250-
Assertions.assertNotSame(loadedObjectToChange, loadedObject);
251-
Assertions.assertNotSame(
252-
loadedObjectToChange.getLazy().get(),
253-
loadedObject.getLazy().get()
254-
);
255-
Assertions.assertEquals(
256-
loadedObjectToChange.getLazy().get().getListOfLazyListOfString().size(),
257-
loadedObject.getLazy().get().getListOfLazyListOfString().size()
258-
);
259-
Assertions.assertEquals(
260-
loadedObjectToChange.getLazy().get().getListOfLazyListOfString().get(0).get().size(),
261-
loadedObject.getLazy().get().getListOfLazyListOfString().get(0).get().size()
262-
);
263-
Assertions.assertEquals(
264-
loadedObjectToChange.getLazy().get().getListOfLazyListOfString().get(0).get().get(0),
265-
loadedObject.getLazy().get().getListOfLazyListOfString().get(0).get().get(0)
266-
);
267-
}
268-
);
229+
this.validateLazyComplexObject(repository, loadedObjectToChange);
269230
}
270231

271232
@Test
272233
void lazyReloadAndRestoreComplexObject(@Autowired final ObjectWithLazyRepository<ComplexLazyObject> repository)
234+
{
235+
prepareLazyComplexObject(repository);
236+
237+
restartDatastore(this.configuration);
238+
239+
final ObjectWithLazy<ComplexLazyObject> loadedObjectToChange = repository.findAll().get(0);
240+
repository.save(loadedObjectToChange);
241+
242+
this.validateLazyComplexObject(repository, loadedObjectToChange);
243+
}
244+
245+
private static ComplexLazyObject prepareLazyComplexObject(
246+
final ObjectWithLazyRepository<ComplexLazyObject> repository)
273247
{
274248
final ObjectWithLazy<ComplexLazyObject> newLazy = new ObjectWithLazy<>();
275249
final ComplexLazyObject objectToStore = new ComplexLazyObject(
276250
SpringDataEclipseStoreLazy.build(new SimpleObject(TestData.DUMMY_STRING)),
277251
new ArrayList<>(Arrays.asList(
278-
SpringDataEclipseStoreLazy.build(new ArrayList<>(Arrays.asList(TestData.DUMMY_STRING))),
279-
SpringDataEclipseStoreLazy.build(new ArrayList<>(Arrays.asList(TestData.DUMMY_STRING_ALTERNATIVE)))
252+
SpringDataEclipseStoreLazy.build(new ArrayList<>(List.of(TestData.DUMMY_STRING))),
253+
SpringDataEclipseStoreLazy.build(new ArrayList<>(List.of(TestData.DUMMY_STRING_ALTERNATIVE)))
280254
))
281255
);
282256
newLazy.setLazy(SpringDataEclipseStoreLazy.build(objectToStore));
283257
repository.save(newLazy);
284258

285-
restartDatastore(this.configuration);
286-
287-
final ObjectWithLazy<ComplexLazyObject> loadedObjectToChange = repository.findAll().get(0);
288-
repository.save(loadedObjectToChange);
289-
259+
return objectToStore;
260+
}
261+
262+
private void validateLazyComplexObject(
263+
final ObjectWithLazyRepository<ComplexLazyObject> repository,
264+
final ObjectWithLazy<ComplexLazyObject> loadedObjectToChange)
265+
{
290266
TestUtil.doBeforeAndAfterRestartOfDatastore(
291267
this.configuration,
292268
() -> {

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/transactions/TransactionsConcurrencyTest.java

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import org.junit.jupiter.api.Assertions;
3030
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.params.ParameterizedTest;
32+
import org.junit.jupiter.params.provider.ValueSource;
3133
import org.springframework.beans.factory.annotation.Autowired;
3234
import org.springframework.test.context.ContextConfiguration;
3335
import org.springframework.transaction.PlatformTransactionManager;
@@ -49,61 +51,31 @@ public TransactionsConcurrencyTest(final AccountRepository accountRepository)
4951
this.accountRepository = accountRepository;
5052
}
5153

52-
@Test
53-
void testSaveConcurrentlyPreviouslyNonExistingAccounts(
54-
@Autowired final PlatformTransactionManager transactionManager
55-
)
56-
throws InterruptedException
57-
{
58-
final List<Account> testAccounts =
59-
IntStream.range(1, 1000).mapToObj((i) -> new Account(i, BigDecimal.TEN)).toList();
60-
61-
final ExecutorService service = Executors.newFixedThreadPool(10);
62-
final CountDownLatch latch = new CountDownLatch(testAccounts.size());
63-
testAccounts.forEach(
64-
account ->
65-
service.execute(() ->
66-
{
67-
new TransactionTemplate(transactionManager).execute(
68-
status ->
69-
{
70-
account.setBalance(account.getBalance().subtract(BigDecimal.ONE));
71-
this.accountRepository.save(account);
72-
return null;
73-
});
74-
Assertions.assertEquals(
75-
BigDecimal.valueOf(9),
76-
this.accountRepository.findById(account.getId()).get().getBalance());
77-
latch.countDown();
78-
}
79-
)
80-
);
81-
82-
assertTrue(latch.await(5, TimeUnit.SECONDS));
83-
84-
final List<Account> accounts = TestUtil.iterableToList(this.accountRepository.findAll());
85-
assertEquals(testAccounts.size(), accounts.size());
86-
accounts.forEach(account -> Assertions.assertEquals(BigDecimal.valueOf(9), account.getBalance()));
87-
}
88-
89-
@Test
90-
void testSaveConcurrentlyPreviouslyExistingAccounts(
91-
@Autowired final PlatformTransactionManager transactionManager)
92-
throws InterruptedException
54+
@ParameterizedTest
55+
@ValueSource(booleans = {false, true})
56+
void saveConcurrently(
57+
final boolean previouslyExisting,
58+
@Autowired final PlatformTransactionManager transactionManager) throws InterruptedException
9359
{
9460
final List<Account> testAccounts =
95-
IntStream.range(1, 100).mapToObj((i) -> new Account(i, BigDecimal.TEN)).toList();
96-
this.accountRepository.saveAll(testAccounts);
61+
IntStream.range(1, 1000).mapToObj(i -> new Account(i, BigDecimal.TEN)).toList();
62+
if(previouslyExisting)
63+
{
64+
this.accountRepository.saveAll(testAccounts);
65+
}
9766

9867
final ExecutorService service = Executors.newFixedThreadPool(10);
9968
final CountDownLatch latch = new CountDownLatch(testAccounts.size());
10069
testAccounts.forEach(
10170
account ->
10271
service.execute(() ->
10372
{
104-
Assertions.assertEquals(
105-
BigDecimal.TEN,
106-
this.accountRepository.findById(account.getId()).get().getBalance());
73+
if(previouslyExisting)
74+
{
75+
Assertions.assertEquals(
76+
BigDecimal.TEN,
77+
this.accountRepository.findById(account.getId()).get().getBalance());
78+
}
10779
new TransactionTemplate(transactionManager).execute(
10880
status ->
10981
{

0 commit comments

Comments
 (0)