|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2000, 2024, Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2000, 2025, Oracle and/or its affiliates. |
3 | 3 | *
|
4 | 4 | * Licensed under the Universal Permissive License v 1.0 as shown at
|
5 | 5 | * https://oss.oracle.com/licenses/upl.
|
6 | 6 | */
|
7 | 7 | package com.tangosol.coherence.config;
|
8 | 8 |
|
9 | 9 | import com.oracle.coherence.common.util.Duration;
|
| 10 | +import com.oracle.coherence.common.util.MemorySize; |
10 | 11 | import com.oracle.coherence.testing.SystemPropertyIsolation;
|
11 | 12 | import com.oracle.coherence.testing.SystemPropertyResource;
|
12 | 13 |
|
@@ -601,6 +602,109 @@ public void testClassPrefixPropertyDefaultingBackwardsCompatible()
|
601 | 602 | assertThat(Config.getInteger(ORACLE_COMMON + RECONNECT_LIMIT_SUFFIX, DEFAULT_VALUE), is(DEFAULT_VALUE));
|
602 | 603 | }
|
603 | 604 |
|
| 605 | + /** |
| 606 | + * COH-32433: ensure no duration magnitude is needed in system property value ending in "Millis" and provided numeric value defaults to millis. |
| 607 | + */ |
| 608 | + @Test |
| 609 | + public void testValidMillisDuration() |
| 610 | + { |
| 611 | + final String ORACLE_COMMON = "com.oracle.common"; // before Coherence 14.1.1.0 |
| 612 | + final String ACKTIMEOUTMILLIS = ".internal.net.socketbus.SocketBusDriver.ackTimeoutMillis"; |
| 613 | + final long dMillis = 1200L; |
| 614 | + |
| 615 | + try (SystemPropertyResource p = new SystemPropertyResource(ORACLE_COMMON + ACKTIMEOUTMILLIS, Long.toString(dMillis));) |
| 616 | + { |
| 617 | + long millis = Config.getDuration(ORACLE_COMMON + ACKTIMEOUTMILLIS, |
| 618 | + new Duration("111", Duration.Magnitude.MILLI), |
| 619 | + Duration.Magnitude.MILLI).as(Duration.Magnitude.MILLI); |
| 620 | + assertThat("system property value does not contain magnitude but defaults to millis as expected for duration for system property ending in Millis", |
| 621 | + millis, is(dMillis)); |
| 622 | + } |
| 623 | + } |
| 624 | + |
| 625 | + @Test |
| 626 | + public void testMillisDurationWithDuration() |
| 627 | + { |
| 628 | + final String ORACLE_COMMON = "com.oracle.common"; // before Coherence 14.1.1.0 |
| 629 | + final String ACKTIMEOUTMILLIS = ".internal.net.socketbus.SocketBusDriver.ackTimeoutMillis"; |
| 630 | + final String sValueSec = "2s"; |
| 631 | + |
| 632 | + try (SystemPropertyResource p = new SystemPropertyResource(ORACLE_COMMON + ACKTIMEOUTMILLIS, sValueSec);) |
| 633 | + { |
| 634 | + long dMillis = Config.getDuration(ORACLE_COMMON + ACKTIMEOUTMILLIS, |
| 635 | + new Duration("111", Duration.Magnitude.MILLI), |
| 636 | + Duration.Magnitude.MILLI).as(Duration.Magnitude.MILLI); |
| 637 | + assertThat("verify specified magnitude in system property value overrides default magnitude", |
| 638 | + dMillis, is(new Duration(sValueSec).as(Duration.Magnitude.MILLI))); |
| 639 | + } |
| 640 | + } |
| 641 | + |
| 642 | + @Test |
| 643 | + public void testInvalidMillisDuration() |
| 644 | + { |
| 645 | + final String ORACLE_COMMON = "com.oracle.common"; |
| 646 | + final String ACKTIMEOUTMILLIS = ".internal.net.socketbus.SocketBusDriver.ackTimeoutMillis"; |
| 647 | + final long dMillis = 1200L; |
| 648 | + |
| 649 | + try (SystemPropertyResource p = new SystemPropertyResource(ORACLE_COMMON + ACKTIMEOUTMILLIS, Long.toString(dMillis));) |
| 650 | + { |
| 651 | + long millis = Config.getDuration(ORACLE_COMMON + ACKTIMEOUTMILLIS, |
| 652 | + new Duration("111", Duration.Magnitude.MILLI)).as(Duration.Magnitude.MILLI); |
| 653 | + assertThat("system property value does not contain magnitude and has no defaults to millis as expected for duration for system property ending in Millis", |
| 654 | + millis, is(111L)); |
| 655 | + } |
| 656 | + } |
| 657 | + |
| 658 | + @Test |
| 659 | + public void testInvalidPropertyValues() |
| 660 | + { |
| 661 | + // test for Int, Long, Float, Double, Duration, MemorySize |
| 662 | + try (SystemPropertyResource p = new SystemPropertyResource("IntProperty", "123InvalidInt");) |
| 663 | + { |
| 664 | + final int DEFAULT = 5; |
| 665 | + int dValue = Config.getInteger("IntProperty", DEFAULT); |
| 666 | + |
| 667 | + assertThat(dValue, is(DEFAULT)); |
| 668 | + } |
| 669 | + try (SystemPropertyResource p = new SystemPropertyResource("LongProperty", "123InvalidLong");) |
| 670 | + { |
| 671 | + final long DEFAULT = 5; |
| 672 | + long lValue = Config.getLong("LongProperty", DEFAULT); |
| 673 | + |
| 674 | + assertThat(lValue, is(DEFAULT)); |
| 675 | + } |
| 676 | + try (SystemPropertyResource p = new SystemPropertyResource("FloatProperty", "123InvalidFloat");) |
| 677 | + { |
| 678 | + final float DEFAULT = 5.0f; |
| 679 | + float fValue = Config.getFloat("FloatProperty", DEFAULT); |
| 680 | + |
| 681 | + assertThat(fValue, is(DEFAULT)); |
| 682 | + } |
| 683 | + try (SystemPropertyResource p = new SystemPropertyResource("DoubleProperty", "123InvalidDouble");) |
| 684 | + { |
| 685 | + final double DEFAULT = 5.0f; |
| 686 | + double fValue = Config.getDouble("DoubleProperty", DEFAULT); |
| 687 | + |
| 688 | + assertThat(fValue, is(DEFAULT)); |
| 689 | + } |
| 690 | + |
| 691 | + try (SystemPropertyResource p = new SystemPropertyResource("DurationProperty", "1234");) |
| 692 | + { |
| 693 | + // missing duration magnitude in string and Config.getDuration() does not provide a default magnitude. |
| 694 | + final Duration DEFAULT = new Duration("5s"); |
| 695 | + Duration durValue = Config.getDuration("DurationProperty", DEFAULT, null); |
| 696 | + |
| 697 | + assertThat(durValue, is(DEFAULT)); |
| 698 | + } |
| 699 | + try (SystemPropertyResource p = new SystemPropertyResource("MemorySizeProperty", "123invalidMagnitude");) |
| 700 | + { |
| 701 | + final MemorySize DEFAULT = new MemorySize("1m"); |
| 702 | + MemorySize memorySize = Config.getMemorySize("MemorySizeProperty", "1m"); |
| 703 | + |
| 704 | + assertThat(memorySize, is(DEFAULT)); |
| 705 | + } |
| 706 | + } |
| 707 | + |
604 | 708 | //----- constants --------------------------------------------------------
|
605 | 709 |
|
606 | 710 | /**
|
|
0 commit comments