|
15 | 15 | */
|
16 | 16 | package org.springframework.data.redis.cache;
|
17 | 17 |
|
18 |
| -import static org.assertj.core.api.Assertions.*; |
19 |
| -import static org.assertj.core.api.Assumptions.*; |
20 |
| - |
21 |
| -import io.netty.util.concurrent.DefaultThreadFactory; |
22 |
| -import lombok.AllArgsConstructor; |
23 |
| -import lombok.Data; |
24 |
| -import lombok.NoArgsConstructor; |
25 |
| -import lombok.RequiredArgsConstructor; |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 20 | +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
| 21 | +import static org.assertj.core.api.Assumptions.assumeThat; |
26 | 22 |
|
27 | 23 | import java.io.Serializable;
|
28 | 24 | import java.nio.charset.StandardCharsets;
|
29 | 25 | import java.time.Duration;
|
30 | 26 | import java.util.Collection;
|
31 | 27 | import java.util.Collections;
|
32 | 28 | import java.util.Date;
|
| 29 | +import java.util.Objects; |
33 | 30 | import java.util.concurrent.CountDownLatch;
|
34 | 31 | import java.util.concurrent.LinkedBlockingDeque;
|
35 | 32 | import java.util.concurrent.ThreadPoolExecutor;
|
|
54 | 51 | import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
|
55 | 52 | import org.springframework.lang.Nullable;
|
56 | 53 |
|
| 54 | +import io.netty.util.concurrent.DefaultThreadFactory; |
| 55 | + |
57 | 56 | /**
|
58 | 57 | * Tests for {@link RedisCache} with {@link DefaultRedisCacheWriter} using different {@link RedisSerializer} and
|
59 | 58 | * {@link RedisConnectionFactory} pairs.
|
|
62 | 61 | * @author Mark Paluch
|
63 | 62 | * @author Piotr Mionskowski
|
64 | 63 | * @author Jos Roseboom
|
| 64 | + * @author John Blum |
65 | 65 | */
|
66 | 66 | @MethodSource("testParams")
|
67 | 67 | public class RedisCacheTests {
|
@@ -225,15 +225,15 @@ void shouldReadAndWriteSimpleCacheKey() {
|
225 | 225 | @ParameterizedRedisTest // DATAREDIS-481
|
226 | 226 | void shouldRejectNonInvalidKey() {
|
227 | 227 |
|
228 |
| - InvalidKey key = new InvalidKey(sample.getFirstame(), sample.getBirthdate()); |
| 228 | + InvalidKey key = new InvalidKey(sample.getFirstname(), sample.getBirthdate()); |
229 | 229 |
|
230 | 230 | assertThatIllegalStateException().isThrownBy(() -> cache.put(key, sample));
|
231 | 231 | }
|
232 | 232 |
|
233 | 233 | @ParameterizedRedisTest // DATAREDIS-481
|
234 | 234 | void shouldAllowComplexKeyWithToStringMethod() {
|
235 | 235 |
|
236 |
| - ComplexKey key = new ComplexKey(sample.getFirstame(), sample.getBirthdate()); |
| 236 | + ComplexKey key = new ComplexKey(sample.getFirstname(), sample.getBirthdate()); |
237 | 237 |
|
238 | 238 | cache.put(key, sample);
|
239 | 239 |
|
@@ -418,31 +418,31 @@ void cacheShouldAllowArrayKeyCacheKeysOfSimpleTypes() {
|
418 | 418 | void cacheShouldAllowListCacheKeysOfComplexTypes() {
|
419 | 419 |
|
420 | 420 | Object key = SimpleKeyGenerator
|
421 |
| - .generateKey(Collections.singletonList(new ComplexKey(sample.getFirstame(), sample.getBirthdate()))); |
| 421 | + .generateKey(Collections.singletonList(new ComplexKey(sample.getFirstname(), sample.getBirthdate()))); |
422 | 422 | cache.put(key, sample);
|
423 | 423 |
|
424 | 424 | ValueWrapper target = cache.get(SimpleKeyGenerator
|
425 |
| - .generateKey(Collections.singletonList(new ComplexKey(sample.getFirstame(), sample.getBirthdate())))); |
| 425 | + .generateKey(Collections.singletonList(new ComplexKey(sample.getFirstname(), sample.getBirthdate())))); |
426 | 426 | assertThat(target.get()).isEqualTo(sample);
|
427 | 427 | }
|
428 | 428 |
|
429 | 429 | @ParameterizedRedisTest // DATAREDIS-1032
|
430 | 430 | void cacheShouldAllowMapCacheKeys() {
|
431 | 431 |
|
432 | 432 | Object key = SimpleKeyGenerator
|
433 |
| - .generateKey(Collections.singletonMap("map-key", new ComplexKey(sample.getFirstame(), sample.getBirthdate()))); |
| 433 | + .generateKey(Collections.singletonMap("map-key", new ComplexKey(sample.getFirstname(), sample.getBirthdate()))); |
434 | 434 | cache.put(key, sample);
|
435 | 435 |
|
436 | 436 | ValueWrapper target = cache.get(SimpleKeyGenerator
|
437 |
| - .generateKey(Collections.singletonMap("map-key", new ComplexKey(sample.getFirstame(), sample.getBirthdate())))); |
| 437 | + .generateKey(Collections.singletonMap("map-key", new ComplexKey(sample.getFirstname(), sample.getBirthdate())))); |
438 | 438 | assertThat(target.get()).isEqualTo(sample);
|
439 | 439 | }
|
440 | 440 |
|
441 | 441 | @ParameterizedRedisTest // DATAREDIS-1032
|
442 | 442 | void cacheShouldFailOnNonConvertibleCacheKey() {
|
443 | 443 |
|
444 | 444 | Object key = SimpleKeyGenerator
|
445 |
| - .generateKey(Collections.singletonList(new InvalidKey(sample.getFirstame(), sample.getBirthdate()))); |
| 445 | + .generateKey(Collections.singletonList(new InvalidKey(sample.getFirstname(), sample.getBirthdate()))); |
446 | 446 | assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> cache.put(key, sample));
|
447 | 447 | }
|
448 | 448 |
|
@@ -537,24 +537,115 @@ void doWithConnection(Consumer<RedisConnection> callback) {
|
537 | 537 | }
|
538 | 538 | }
|
539 | 539 |
|
540 |
| - @Data |
541 |
| - @NoArgsConstructor |
542 |
| - @AllArgsConstructor |
543 | 540 | static class Person implements Serializable {
|
544 |
| - String firstame; |
545 |
| - Date birthdate; |
| 541 | + |
| 542 | + private String firstname; |
| 543 | + private Date birthdate; |
| 544 | + |
| 545 | + public Person() { } |
| 546 | + |
| 547 | + public Person(String firstname, Date birthdate) { |
| 548 | + this.firstname = firstname; |
| 549 | + this.birthdate = birthdate; |
| 550 | + } |
| 551 | + |
| 552 | + public String getFirstname() { |
| 553 | + return this.firstname; |
| 554 | + } |
| 555 | + |
| 556 | + public void setFirstname(String firstname) { |
| 557 | + this.firstname = firstname; |
| 558 | + } |
| 559 | + |
| 560 | + public Date getBirthdate() { |
| 561 | + return this.birthdate; |
| 562 | + } |
| 563 | + |
| 564 | + public void setBirthdate(Date birthdate) { |
| 565 | + this.birthdate = birthdate; |
| 566 | + } |
| 567 | + |
| 568 | + @Override |
| 569 | + public boolean equals(Object obj) { |
| 570 | + |
| 571 | + if (this == obj) { |
| 572 | + return true; |
| 573 | + } |
| 574 | + |
| 575 | + if (!(obj instanceof Person that)) { |
| 576 | + return false; |
| 577 | + } |
| 578 | + |
| 579 | + return Objects.equals(this.getFirstname(), that.getFirstname()) |
| 580 | + && Objects.equals(this.getBirthdate(), that.getBirthdate()); |
| 581 | + } |
| 582 | + |
| 583 | + @Override |
| 584 | + public int hashCode() { |
| 585 | + return Objects.hash(getFirstname(), getBirthdate()); |
| 586 | + } |
| 587 | + |
| 588 | + @Override |
| 589 | + public String toString() { |
| 590 | + return "RedisCacheTests.Person(firstname=" + this.getFirstname() |
| 591 | + + ", birthdate=" + this.getBirthdate() + ")"; |
| 592 | + } |
546 | 593 | }
|
547 | 594 |
|
548 |
| - @RequiredArgsConstructor // toString not overridden |
| 595 | + // toString not overridden |
549 | 596 | static class InvalidKey implements Serializable {
|
550 |
| - final String firstame; |
| 597 | + |
| 598 | + final String firstname; |
551 | 599 | final Date birthdate;
|
| 600 | + |
| 601 | + public InvalidKey(String firstname, Date birthdate) { |
| 602 | + this.firstname = firstname; |
| 603 | + this.birthdate = birthdate; |
| 604 | + } |
552 | 605 | }
|
553 | 606 |
|
554 |
| - @Data |
555 |
| - @RequiredArgsConstructor |
556 | 607 | static class ComplexKey implements Serializable {
|
557 |
| - final String firstame; |
| 608 | + |
| 609 | + final String firstname; |
558 | 610 | final Date birthdate;
|
| 611 | + |
| 612 | + public ComplexKey(String firstname, Date birthdate) { |
| 613 | + this.firstname = firstname; |
| 614 | + this.birthdate = birthdate; |
| 615 | + } |
| 616 | + |
| 617 | + public String getFirstname() { |
| 618 | + return this.firstname; |
| 619 | + } |
| 620 | + |
| 621 | + public Date getBirthdate() { |
| 622 | + return this.birthdate; |
| 623 | + } |
| 624 | + |
| 625 | + @Override |
| 626 | + public boolean equals(final Object obj) { |
| 627 | + |
| 628 | + if (this == obj) { |
| 629 | + return true; |
| 630 | + } |
| 631 | + |
| 632 | + if (!(obj instanceof ComplexKey that)) { |
| 633 | + return false; |
| 634 | + } |
| 635 | + |
| 636 | + return Objects.equals(this.getFirstname(), that.getFirstname()) |
| 637 | + && Objects.equals(this.getBirthdate(), that.getBirthdate()); |
| 638 | + } |
| 639 | + |
| 640 | + @Override |
| 641 | + public int hashCode() { |
| 642 | + return Objects.hash(getFirstname(), getBirthdate()); |
| 643 | + } |
| 644 | + |
| 645 | + @Override |
| 646 | + public String toString() { |
| 647 | + return "RedisCacheTests.ComplexKey(firstame=" + this.getFirstname() |
| 648 | + + ", birthdate=" + this.getBirthdate() + ")"; |
| 649 | + } |
559 | 650 | }
|
560 | 651 | }
|
0 commit comments