├── .gitignore ├── .travis.yml ├── LICENSE ├── README.adoc ├── assertions-disabled ├── pom.xml └── src │ └── main │ └── java │ └── net │ └── openhft │ └── chronicle │ └── assertions │ └── AssertUtil.java ├── assertions-enabled ├── pom.xml └── src │ └── main │ └── java │ └── net │ └── openhft │ └── chronicle │ └── assertions │ └── AssertUtil.java ├── benchmarks ├── pom.xml └── src │ └── main │ └── java │ ├── CopyMemoryJLBH.java │ ├── MapBenchMain.java │ └── net │ └── openhft │ └── chronicle │ └── core │ └── benchmark │ ├── AsDoubleImplementationPerfJLBH.java │ ├── Interrupted.java │ ├── Main.java │ ├── MatrixMain.java │ ├── StringUtilsEqualsCaseIgnoreBaseJLBH.java │ ├── StringUtilsEqualsCaseIgnoreBestCaseJLBH.java │ ├── StringUtilsEqualsCaseIgnoreWorstCaseJLBH.java │ └── TimeProviders.java ├── checked-exceptions ├── README.adoc ├── pom.xml └── src │ └── main │ └── java │ └── java │ ├── lang │ ├── Appendable.java │ ├── ArithmeticException.java │ ├── CharSequence.java │ ├── IllegalArgumentException.java │ └── IllegalStateException.java │ └── nio │ ├── BufferOverflowException.java │ └── BufferUnderflowException.java ├── images ├── Core_line.png └── placeholder.txt ├── pom.xml ├── src ├── main │ ├── adoc │ │ └── StackTrace-user-guide.adoc │ ├── java │ │ └── net │ │ │ └── openhft │ │ │ └── chronicle │ │ │ └── core │ │ │ ├── Bootstrap.java │ │ │ ├── ChronicleInit.java │ │ │ ├── ChronicleInitRunnable.java │ │ │ ├── Jvm.java │ │ │ ├── LicenceCheck.java │ │ │ ├── Maths.java │ │ │ ├── Memory.java │ │ │ ├── Mocker.java │ │ │ ├── OS.java │ │ │ ├── StackTrace.java │ │ │ ├── UnsafeMemory.java │ │ │ ├── analytics │ │ │ ├── AnalyticsFacade.java │ │ │ └── package-info.java │ │ │ ├── annotation │ │ │ ├── ChronicleFeature.java │ │ │ ├── DontChain.java │ │ │ ├── ForceInline.java │ │ │ ├── HotMethod.java │ │ │ ├── Java9.java │ │ │ ├── Negative.java │ │ │ ├── NonNegative.java │ │ │ ├── NonPositive.java │ │ │ ├── PackageLocal.java │ │ │ ├── Positive.java │ │ │ ├── Range.java │ │ │ ├── RequiredForClient.java │ │ │ ├── ScopeConfined.java │ │ │ ├── SingleThreaded.java │ │ │ ├── TargetMajorVersion.java │ │ │ ├── UsedViaReflection.java │ │ │ └── package-info.java │ │ │ ├── announcer │ │ │ ├── Announcer.java │ │ │ └── package-info.java │ │ │ ├── cleaner │ │ │ ├── CleanerServiceLocator.java │ │ │ ├── package-info.java │ │ │ └── spi │ │ │ │ ├── ByteBufferCleanerService.java │ │ │ │ └── package-info.java │ │ │ ├── cooler │ │ │ ├── CoolerTester.java │ │ │ ├── CpuCooler.java │ │ │ ├── CpuCoolers.java │ │ │ └── package-info.java │ │ │ ├── domestic │ │ │ └── package-info.java │ │ │ ├── internal │ │ │ ├── AnnotationFinder.java │ │ │ ├── Bootstrap.java │ │ │ ├── ChronicleGuarding.java │ │ │ ├── ClassUtil.java │ │ │ ├── CloseableUtils.java │ │ │ ├── CpuClass.java │ │ │ ├── PackageNameUtil.java │ │ │ ├── ReferenceCountedUtils.java │ │ │ ├── analytics │ │ │ │ ├── MuteAnalytics.java │ │ │ │ ├── MuteBuilder.java │ │ │ │ ├── ReflectionUtil.java │ │ │ │ ├── ReflectiveAnalytics.java │ │ │ │ ├── ReflectiveBuilder.java │ │ │ │ └── StandardMaps.java │ │ │ ├── announcer │ │ │ │ └── InternalAnnouncer.java │ │ │ ├── cleaner │ │ │ │ ├── Jdk9ByteBufferCleanerService.java │ │ │ │ └── ReflectionBasedByteBufferCleanerService.java │ │ │ ├── invariant │ │ │ │ ├── ints │ │ │ │ │ └── IntCondition.java │ │ │ │ └── longs │ │ │ │ │ └── LongCondition.java │ │ │ ├── package-info.java │ │ │ ├── pom │ │ │ │ └── InternalPomProperties.java │ │ │ └── util │ │ │ │ ├── DirectBufferUtil.java │ │ │ │ ├── MapUtil.java │ │ │ │ ├── NopThreadConfinementAsserter.java │ │ │ │ ├── RangeUtil.java │ │ │ │ ├── ThreadConfinementLifecycle.java │ │ │ │ └── VanillaThreadConfinementAsserter.java │ │ │ ├── io │ │ │ ├── AbstractCloseable.java │ │ │ ├── AbstractCloseableReferenceCounted.java │ │ │ ├── AbstractReferenceCounted.java │ │ │ ├── BackgroundResourceReleaser.java │ │ │ ├── CleaningRandomAccessFile.java │ │ │ ├── Closeable.java │ │ │ ├── ClosedIORuntimeException.java │ │ │ ├── ClosedIllegalStateException.java │ │ │ ├── ClosedState.java │ │ │ ├── IORuntimeException.java │ │ │ ├── IOTools.java │ │ │ ├── InvalidMarshallableException.java │ │ │ ├── ManagedCloseable.java │ │ │ ├── MonitorReferenceCounted.java │ │ │ ├── Monitorable.java │ │ │ ├── QueryCloseable.java │ │ │ ├── ReferenceChangeListener.java │ │ │ ├── ReferenceChangeListenerManager.java │ │ │ ├── ReferenceCounted.java │ │ │ ├── ReferenceCountedTracer.java │ │ │ ├── ReferenceOwner.java │ │ │ ├── Resettable.java │ │ │ ├── SimpleCloseable.java │ │ │ ├── SingleThreadedChecked.java │ │ │ ├── Syncable.java │ │ │ ├── ThreadingIllegalStateException.java │ │ │ ├── TracingReferenceCounted.java │ │ │ ├── UnsafeCloseable.java │ │ │ ├── Validatable.java │ │ │ ├── ValidatableUtil.java │ │ │ ├── VanillaReferenceCounted.java │ │ │ ├── VanillaReferenceOwner.java │ │ │ ├── Wget.java │ │ │ └── package-info.java │ │ │ ├── onoes │ │ │ ├── ChainedExceptionHandler.java │ │ │ ├── ExceptionHandler.java │ │ │ ├── ExceptionKey.java │ │ │ ├── LogLevel.java │ │ │ ├── NullExceptionHandler.java │ │ │ ├── RecordingExceptionHandler.java │ │ │ ├── Slf4jExceptionHandler.java │ │ │ ├── ThreadLocalisedExceptionHandler.java │ │ │ └── package-info.java │ │ │ ├── pom │ │ │ └── PomProperties.java │ │ │ ├── pool │ │ │ ├── ClassAliasPool.java │ │ │ ├── ClassLookup.java │ │ │ ├── DynamicEnumClass.java │ │ │ ├── EnumCache.java │ │ │ ├── EnumInterner.java │ │ │ ├── ParsingCache.java │ │ │ ├── StaticEnumClass.java │ │ │ ├── StringBuilderPool.java │ │ │ ├── StringInterner.java │ │ │ └── package-info.java │ │ │ ├── scoped │ │ │ ├── AbstractScopedResource.java │ │ │ ├── ScopedResource.java │ │ │ ├── ScopedResourcePool.java │ │ │ ├── ScopedThreadLocal.java │ │ │ ├── StrongReferenceScopedResource.java │ │ │ └── WeakReferenceScopedResource.java │ │ │ ├── shutdown │ │ │ ├── Hooklet.java │ │ │ ├── PriorityHook.java │ │ │ └── package-info.java │ │ │ ├── threads │ │ │ ├── CancellableTimer.java │ │ │ ├── CleaningThread.java │ │ │ ├── CleaningThreadLocal.java │ │ │ ├── DelegatingEventLoop.java │ │ │ ├── EventHandler.java │ │ │ ├── EventLoop.java │ │ │ ├── HandlerPriority.java │ │ │ ├── InterruptedRuntimeException.java │ │ │ ├── InvalidEventHandlerException.java │ │ │ ├── JitterSampler.java │ │ │ ├── OnDemandEventLoop.java │ │ │ ├── ThreadDump.java │ │ │ ├── ThreadLocalHelper.java │ │ │ ├── Timer.java │ │ │ ├── VanillaEventHandler.java │ │ │ └── package-info.java │ │ │ ├── time │ │ │ ├── LongTime.java │ │ │ ├── PosixTimeProvider.java │ │ │ ├── SetTimeProvider.java │ │ │ ├── SystemTimeProvider.java │ │ │ ├── TimeProvider.java │ │ │ └── UniqueMicroTimeProvider.java │ │ │ ├── util │ │ │ ├── AbstractInvocationHandler.java │ │ │ ├── BooleanConsumer.java │ │ │ ├── Builder.java │ │ │ ├── ByteConsumer.java │ │ │ ├── CharConsumer.java │ │ │ ├── CharSequenceComparator.java │ │ │ ├── CharToBooleanFunction.java │ │ │ ├── ClassLocal.java │ │ │ ├── ClassMetrics.java │ │ │ ├── ClassNotFoundRuntimeException.java │ │ │ ├── CompilerUtils.java │ │ │ ├── CoreDynamicEnum.java │ │ │ ├── FloatConsumer.java │ │ │ ├── GenericReflection.java │ │ │ ├── Histogram.java │ │ │ ├── IgnoresEverything.java │ │ │ ├── Ints.java │ │ │ ├── InvocationTargetRuntimeException.java │ │ │ ├── Longs.java │ │ │ ├── MisAlignedAssertionError.java │ │ │ ├── Mocker.java │ │ │ ├── NanoSampler.java │ │ │ ├── ObjBooleanConsumer.java │ │ │ ├── ObjByteConsumer.java │ │ │ ├── ObjCharConsumer.java │ │ │ ├── ObjFloatConsumer.java │ │ │ ├── ObjShortConsumer.java │ │ │ ├── ObjectUtils.java │ │ │ ├── ReadResolvable.java │ │ │ ├── RecordingHistogram.java │ │ │ ├── SerializableBiFunction.java │ │ │ ├── SerializableConsumer.java │ │ │ ├── SerializableFunction.java │ │ │ ├── SerializablePredicate.java │ │ │ ├── SerializableUpdater.java │ │ │ ├── SerializableUpdaterWithArg.java │ │ │ ├── ShortConsumer.java │ │ │ ├── SimpleCleaner.java │ │ │ ├── StringUtils.java │ │ │ ├── ThreadConfinementAsserter.java │ │ │ ├── ThrowingBiConsumer.java │ │ │ ├── ThrowingBiFunction.java │ │ │ ├── ThrowingCallable.java │ │ │ ├── ThrowingConsumer.java │ │ │ ├── ThrowingConsumerNonCapturing.java │ │ │ ├── ThrowingFunction.java │ │ │ ├── ThrowingIntSupplier.java │ │ │ ├── ThrowingLongSupplier.java │ │ │ ├── ThrowingRunnable.java │ │ │ ├── ThrowingSupplier.java │ │ │ ├── ThrowingTriFunction.java │ │ │ ├── Time.java │ │ │ ├── TypeOf.java │ │ │ ├── UnresolvedType.java │ │ │ ├── Updater.java │ │ │ └── WeakIdentityHashMap.java │ │ │ └── values │ │ │ ├── BooleanValue.java │ │ │ ├── ByteValue.java │ │ │ ├── CharValue.java │ │ │ ├── DoubleValue.java │ │ │ ├── FloatValue.java │ │ │ ├── IntArrayValues.java │ │ │ ├── IntValue.java │ │ │ ├── LongArrayValues.java │ │ │ ├── LongValue.java │ │ │ ├── MaxBytes.java │ │ │ ├── ShortValue.java │ │ │ ├── StringValue.java │ │ │ ├── TwoLongValue.java │ │ │ └── package-info.java │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService │ │ └── net │ │ └── openhft │ │ └── chronicle │ │ └── core │ │ └── onoes │ │ ├── Google.properties │ │ └── Stackoverflow.properties └── test │ ├── java │ ├── ClassWithNoPackageTest.java │ └── net │ │ └── openhft │ │ └── chronicle │ │ └── core │ │ ├── ChronicleInitRunnableTest.java │ │ ├── ChronicleInitTest.java │ │ ├── ClassLocalTest.java │ │ ├── CleaningRandomAccessFileTest.java │ │ ├── CoreTestCommon.java │ │ ├── JvmMain.java │ │ ├── JvmParseSizeTest.java │ │ ├── JvmSafepointTest.java │ │ ├── JvmTest.java │ │ ├── LicenceCheckTest.java │ │ ├── MathsTest.java │ │ ├── MemoryTest.java │ │ ├── MockerTest.java │ │ ├── NotNullIntrumentationTargetTest.java │ │ ├── OSTest.java │ │ ├── PerformanceTuningTest.java │ │ ├── RandomAccessFileCleanupMain.java │ │ ├── SleepTesterMain.java │ │ ├── StackTraceTest.java │ │ ├── UnsafeMemory2Test.java │ │ ├── UnsafeMemoryByteTest.java │ │ ├── UnsafeMemoryIntTest.java │ │ ├── UnsafeMemoryLongTest.java │ │ ├── UnsafeMemoryShortTest.java │ │ ├── UnsafeMemoryTest.java │ │ ├── UnsafeMemoryTestMixin.java │ │ ├── UnsafePingPointMain.java │ │ ├── ZeroCostAssertionStatusTest.java │ │ ├── annotation │ │ └── ScopeConfinedTest.java │ │ ├── announcer │ │ └── AnnouncerTest.java │ │ ├── benchmarks │ │ └── Randomness.java │ │ ├── cleaner │ │ └── impl │ │ │ ├── CleanerTestUtil.java │ │ │ ├── jdk9 │ │ │ └── Jdk9ByteBufferCleanerServiceTest.java │ │ │ └── reflect │ │ │ └── ReflectionBasedByteBufferCleanerServiceTest.java │ │ ├── cooler │ │ ├── CoolerTesterTest.java │ │ └── CpuCoolersTest.java │ │ ├── internal │ │ ├── CloseableUtilsTest.java │ │ ├── CpuClassTest.java │ │ ├── JvmExceptionTracker.java │ │ ├── ReferenceCountedUtilsTest.java │ │ ├── analytics │ │ │ ├── AnalyticsFacadeTest.java │ │ │ ├── ReflectionUtilTest.java │ │ │ └── StandardMapsTest.java │ │ ├── cleaner │ │ │ ├── Jdk9ByteBufferCleanerServiceTest.java │ │ │ └── ReflectionBasedByteBufferCleanerServiceTest.java │ │ └── util │ │ │ ├── DirectBufferUtilTest.java │ │ │ ├── NopThreadConfinementAsserterTest.java │ │ │ └── VanillaThreadConfinementAsserterTest.java │ │ ├── io │ │ ├── AbstractCloseableReferenceCountedTest.java │ │ ├── AbstractCloseableTest.java │ │ ├── AbstractReferenceCountedTest.java │ │ ├── BackgroundResourceReleaserMain.java │ │ ├── BackgroundResourceReleaserTest.java │ │ ├── CleaningRandomAccessFileTest.java │ │ ├── CloseableTest.java │ │ ├── ClosedIORuntimeExceptionTest.java │ │ ├── IOBenchmarkMain.java │ │ ├── IORuntimeExceptionTest.java │ │ ├── IOToolsTest.java │ │ ├── ManagedCloseableTest.java │ │ ├── MonitorReferenceCountedContractTest.java │ │ ├── ReferenceChangeListenerTest.java │ │ ├── ReferenceCountedContractTest.java │ │ ├── ReferenceCountedTracerContractTest.java │ │ ├── ReferenceOwnerTest.java │ │ ├── SimpleCloseableTest.java │ │ ├── SyncableTest.java │ │ ├── ThreadingIllegalStateExceptionTest.java │ │ ├── TracingReferenceCountedTest.java │ │ ├── UnsafeCloseableTest.java │ │ ├── ValidatableTest.java │ │ ├── ValidatableUtilTest.java │ │ ├── VanillaReferenceCountedTest.java │ │ └── WgetTest.java │ │ ├── jitter │ │ └── LongPingPongMain.java │ │ ├── onoes │ │ ├── ChainedExceptionHandlerTest.java │ │ ├── ExceptionHandlerTest.java │ │ ├── ExceptionKeyTest.java │ │ ├── NullExceptionHandlerTest.java │ │ ├── RecordingExceptionHandlerTest.java │ │ ├── Slf4jExceptionHandlerTest.java │ │ └── ThreadLocalisedExceptionHandlerTest.java │ │ ├── pom │ │ └── PomPropertiesTest.java │ │ ├── pool │ │ ├── ClassAliasPoolTest.java │ │ ├── ClassLookupTest.java │ │ ├── DynamicEnumPooledClassTest.java │ │ ├── Ecn.java │ │ ├── EcnDynamic.java │ │ ├── EnumCacheTest.java │ │ ├── EnumInternerTest.java │ │ ├── ParsingCacheTest.java │ │ ├── StaticEnumClassTest.java │ │ ├── StringInternerTest.java │ │ └── YesNo.java │ │ ├── scoped │ │ ├── ScopedThreadLocalTest.java │ │ └── WeakReferenceScopedResourceTest.java │ │ ├── shutdown │ │ ├── HookletTest.java │ │ └── PriorityHookTest.java │ │ ├── threads │ │ ├── CancellableTimerTest.java │ │ ├── CleaningThreadLocalTest.java │ │ ├── CleaningThreadTest.java │ │ ├── DelegatingEventLoopTest.java │ │ ├── EventHandlerTest.java │ │ ├── EventLoopTest.java │ │ ├── HandlerPriorityTest.java │ │ ├── InterruptedRuntimeExceptionTest.java │ │ ├── InvalidEventHandlerExceptionTest.java │ │ ├── OnDemandEventLoopTest.java │ │ ├── ReferenceQueue.java │ │ ├── ThreadDumpTest.java │ │ ├── ThreadLocalHelperTest.java │ │ └── TimerTest.java │ │ ├── time │ │ ├── LongTimeTest.java │ │ ├── PosixTimeProviderTest.java │ │ ├── SetTimeProviderTest.java │ │ ├── SystemTimeProviderTest.java │ │ └── UniqueMicroTimeProviderTest.java │ │ ├── util │ │ ├── AbstractInvocationHandlerTest.java │ │ ├── BuilderTest.java │ │ ├── ByteConsumerTest.java │ │ ├── CharSequenceComparatorTest.java │ │ ├── ClassMetricsTest.java │ │ ├── ClassNotFoundRuntimeExceptionTest.java │ │ ├── CompilerUtilsTest.java │ │ ├── GenericReflectionTest.java │ │ ├── HistogramTest.java │ │ ├── IgnoresEverythingTest.java │ │ ├── IntConditionTest.java │ │ ├── InvocationTargetRuntimeExceptionTest.java │ │ ├── MyClass.java │ │ ├── ObjectUtilsConvertToTest.java │ │ ├── ObjectUtilsTest.java │ │ ├── ReadResolvableTest.java │ │ ├── RecordingHistogramTest.java │ │ ├── SimpleCleanerTest.java │ │ ├── StringUtilsTest.java │ │ ├── ThreadConfinementAsserterTest.java │ │ ├── ThrowingFunctionTest.java │ │ ├── ThrowingSupplierTest.java │ │ ├── TypeOfTest.java │ │ ├── UnresolvedTypeTest.java │ │ ├── UpdaterTest.java │ │ └── WeakIdentityHashMapTest.java │ │ └── values │ │ ├── IntValueTest.java │ │ ├── LongValueImpl.java │ │ ├── LongValueImplTest.java │ │ └── LongValueTest.java │ └── resources │ ├── META-INF │ └── services │ │ ├── net.openhft.chronicle.core.ChronicleInitRunnable │ │ └── net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService │ ├── readFileManyTimes.txt │ ├── sample.system.properties │ ├── test.expiry-date │ └── test2.expiry-date ├── system.properties └── systemProperties.adoc /.gitignore: -------------------------------------------------------------------------------- 1 | ### How to update 2 | # This is copied from OpenHFT/.gitignore 3 | # update the original and run OpenHFT/update_gitignore.sh 4 | 5 | ### AIDE 6 | aide/ 7 | aide.ignore 8 | 9 | ### Compiled class file 10 | *.class 11 | 12 | ### Package Files 13 | *.jar 14 | *.war 15 | *.ear 16 | 17 | ### Log file 18 | *.log 19 | 20 | ### IntelliJ 21 | *.iml 22 | *.ipr 23 | *.iws 24 | .idea 25 | compat_reports 26 | .attach_pid* 27 | 28 | ### Virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 29 | hs_err_pid* 30 | 31 | ### Maven template 32 | target/ 33 | pom.xml.tag 34 | pom.xml.releaseBackup 35 | pom.xml.versionsBackup 36 | pom.xml.next 37 | release.properties 38 | 39 | ### Eclipse template 40 | *.pydevproject 41 | .metadata 42 | .gradle 43 | bin/ 44 | tmp/ 45 | *.tmp 46 | *.bak 47 | *.swp 48 | *~.nib 49 | local.properties 50 | .classpath 51 | .project 52 | .settings/ 53 | .loadpath 54 | 55 | ### Queue files 56 | *.cq4t 57 | *.cq4 58 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 -------------------------------------------------------------------------------- /benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/StringUtilsEqualsCaseIgnoreBestCaseJLBH.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.benchmark; 2 | 3 | import static net.openhft.chronicle.core.benchmark.StringUtilsEqualsCaseIgnoreBaseJLBH.generate; 4 | 5 | public class StringUtilsEqualsCaseIgnoreBestCaseJLBH { 6 | public static void main(String[] args) { 7 | StringUtilsEqualsCaseIgnoreBaseJLBH.run( 8 | StringUtilsEqualsCaseIgnoreBestCaseJLBH.class, 9 | () -> generate(() -> 'a', 100), 10 | () -> generate(() -> 'a', 100) 11 | ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/StringUtilsEqualsCaseIgnoreWorstCaseJLBH.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.benchmark; 2 | 3 | import static net.openhft.chronicle.core.benchmark.StringUtilsEqualsCaseIgnoreBaseJLBH.generate; 4 | 5 | public class StringUtilsEqualsCaseIgnoreWorstCaseJLBH { 6 | public static void main(String[] args) { 7 | // Test two strings of entirely different case for their duration 8 | StringUtilsEqualsCaseIgnoreBaseJLBH.run( 9 | StringUtilsEqualsCaseIgnoreWorstCaseJLBH.class, 10 | () -> generate(() -> 'A', 100), 11 | () -> generate(() -> 'a', 100) 12 | ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /checked-exceptions/README.adoc: -------------------------------------------------------------------------------- 1 | = README 2 | 3 | This adds checked versions of a number of common unchecked exceptions we have. 4 | 5 | We can add these temporaily as we don't expect developers to be force to handle these exceptions but we want to ensure 6 | 7 | - we want handle these correctly in our code. 8 | - we want handle these consistently with the right exception and making these checked helps review the choices made. 9 | - we want to document when these unchecked exceptions can/cannot occur. 10 | -------------------------------------------------------------------------------- /checked-exceptions/src/main/java/java/lang/ArithmeticException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class ArithmeticException extends Exception { 4 | public ArithmeticException(String s) { 5 | super(s); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /checked-exceptions/src/main/java/java/lang/IllegalArgumentException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class IllegalArgumentException extends Exception { 4 | public IllegalArgumentException() { 5 | } 6 | 7 | public IllegalArgumentException(String message) { 8 | super(message); 9 | } 10 | 11 | public IllegalArgumentException(Throwable cause) { 12 | super(cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /checked-exceptions/src/main/java/java/lang/IllegalStateException.java: -------------------------------------------------------------------------------- 1 | package java.lang; 2 | 3 | public class IllegalStateException extends Exception { 4 | public IllegalStateException(String message) { 5 | super(message); 6 | } 7 | 8 | public IllegalStateException(Throwable cause) { 9 | super(cause); 10 | } 11 | 12 | public IllegalStateException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /checked-exceptions/src/main/java/java/nio/BufferOverflowException.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | public class BufferOverflowException extends Exception { 4 | } 5 | -------------------------------------------------------------------------------- /checked-exceptions/src/main/java/java/nio/BufferUnderflowException.java: -------------------------------------------------------------------------------- 1 | package java.nio; 2 | 3 | public class BufferUnderflowException extends Exception { 4 | } 5 | -------------------------------------------------------------------------------- /images/Core_line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Core/91a2db2ec698cb45e9133f529c79d13815349edc/images/Core_line.png -------------------------------------------------------------------------------- /images/placeholder.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/Bootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core; 20 | 21 | import net.openhft.chronicle.core.internal.ChronicleGuarding; 22 | 23 | /** 24 | * Contains the pieces which must be loaded first 25 | */ 26 | public class Bootstrap { 27 | static { 28 | ChronicleGuarding.bootstrap(); 29 | } 30 | 31 | @SuppressWarnings("EmptyMethod") 32 | public static void bootstrap() { 33 | // used to trigger static initializers 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/ChronicleInitRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core; 20 | 21 | public interface ChronicleInitRunnable extends Runnable { 22 | /** 23 | * This method will be run once at the end of Jvm.class static initialization. 24 | */ 25 | default void postInit() { 26 | // No-op. 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/analytics/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides functionality for reporting analytics to an upstream receiver, primarily Google Analytics. 3 | * 4 | *

The {@link net.openhft.chronicle.core.analytics.AnalyticsFacade} is an interface which is designed 5 | * to provide a means for libraries to report analytics to an upstream receiver. It provides a best-effort 6 | * mechanism for propagating events to Google Analytics. This interface has methods for sending events 7 | * with or without additional parameters and also for enabling or disabling analytics reporting. 8 | * 9 | *

Furthermore, it has an internal builder that can be used to build an instance of AnalyticsFacade with 10 | * custom configurations like frequency limits, custom loggers for error and debug messages, custom URL for 11 | * Google Analytics, and more. 12 | * 13 | *

This package is part of the Chronicle Core library which provides utilities and low-level support 14 | * for higher-level components. 15 | * 16 | * @see net.openhft.chronicle.core.analytics.AnalyticsFacade 17 | */ 18 | package net.openhft.chronicle.core.analytics; 19 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/ChronicleFeature.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.TYPE}) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface ChronicleFeature { 11 | int value(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/DontChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.annotation; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * This annotation, when applied to an interface, instructs that the interface should not be considered when MethodReaders and MethodWriters 27 | * are exploring interfaces to implement. It provides a mechanism to exclude certain interfaces from being processed by these components. 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.TYPE) 31 | public @interface DontChain { 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/ForceInline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.annotation; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Marker annotation for some methods and constructors in the JSR 292 implementation. 28 | *

29 | * To utilise this annotation see Chronicle Enterprise Warmup module. 30 | */ 31 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | public @interface ForceInline { 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/HotMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.annotation; 20 | 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.METHOD) 30 | public @interface HotMethod { 31 | @NotNull String value() default ""; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/Java9.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.annotation; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Marker annotation to label methods that are expected to be called by java-9+ specific code paths. 27 | */ 28 | @Retention(RetentionPolicy.SOURCE) 29 | @Target(ElementType.METHOD) 30 | public @interface Java9 { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/Negative.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.annotation; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Annotation that indicates the annotated element is expected to hold a negative value (i.e. {@code val < 0}). 28 | * This can be applied to methods, fields, parameters, local variables, and types to specify constraints 29 | * or document the intended usage. 30 | * 31 | * @see NonNegative 32 | * @see NonPositive 33 | * @see Positive 34 | * @see Range 35 | */ 36 | @Retention(RetentionPolicy.CLASS) 37 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) 38 | public @interface Negative { 39 | 40 | /** 41 | * Specifies an optional comment to provide additional context or rationale for why the 42 | * annotated element must have a negative value. 43 | * 44 | * @return the comment explaining why this constraint is necessary 45 | */ 46 | String value() default ""; 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/NonNegative.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.annotation; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Annotation that indicates the annotated element is expected to hold a non-negative value (i.e. {@code val >= 0}). 28 | * This can be applied to methods, fields, parameters, local variables, and types to specify constraints 29 | * or document the intended usage. 30 | * 31 | * @see Negative 32 | * @see NonPositive 33 | * @see Positive 34 | * @see Range 35 | */ 36 | @Retention(RetentionPolicy.CLASS) 37 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) 38 | public @interface NonNegative { 39 | 40 | /** 41 | * Specifies an optional comment to provide additional context or rationale for why the 42 | * annotated element must have a non-negative value. 43 | * 44 | * @return the comment explaining why this constraint is necessary 45 | */ 46 | String value() default ""; 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/NonPositive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.annotation; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Annotation that indicates the annotated element is expected to hold a non-positive value (i.e. {@code val <= 0}). 28 | * This can be applied to methods, fields, parameters, local variables, and types to specify constraints 29 | * or document the intended usage. 30 | * 31 | * @see Negative 32 | * @see NonNegative 33 | * @see Positive 34 | */ 35 | @Retention(RetentionPolicy.CLASS) 36 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) 37 | public @interface NonPositive { 38 | 39 | /** 40 | * Specifies an optional comment to provide additional context or rationale for why the 41 | * annotated element must have a non-positive value. 42 | * 43 | * @return the comment explaining why this constraint is necessary 44 | */ 45 | String value() default ""; 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/PackageLocal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.annotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.Target; 23 | 24 | import static java.lang.annotation.ElementType.*; 25 | import static java.lang.annotation.RetentionPolicy.SOURCE; 26 | 27 | /** 28 | * Annotation to indicate that the annotated element has package-local visibility 29 | * intentionally, usually to avoid accessor methods. This annotation serves as 30 | * documentation to inform others of the deliberate design choice. 31 | */ 32 | @Documented 33 | @Retention(SOURCE) 34 | @Target({METHOD, FIELD, CONSTRUCTOR, TYPE}) 35 | public @interface PackageLocal { 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/Positive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.annotation; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Annotation that indicates the annotated element is expected to hold a positive value (i.e. {@code val > 0}). 28 | * This can be applied to methods, fields, parameters, local variables, and types to specify constraints 29 | * or document the intended usage. 30 | * 31 | * @see Negative 32 | * @see NonNegative 33 | * @see NonPositive 34 | */ 35 | @Retention(RetentionPolicy.CLASS) 36 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) 37 | public @interface Positive { 38 | 39 | /** 40 | * Specifies an optional comment to provide additional context or rationale for why the 41 | * annotated element must have a positive value. 42 | * 43 | * @return the comment explaining why this constraint is necessary 44 | */ 45 | String value() default ""; 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/RequiredForClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.annotation; 19 | 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | 23 | /** 24 | * Indicates that modifications to the annotated class should be made with caution 25 | * as it is known to be used by a client. This annotation serves as a warning to 26 | * developers, reminding them of the implications of changes to the annotated element. 27 | */ 28 | @Retention(RetentionPolicy.SOURCE) 29 | public @interface RequiredForClient { 30 | 31 | /** 32 | * Specifies an optional comment to provide additional context or information 33 | * about where this class is referred to. 34 | * 35 | * @return the comment providing more details 36 | */ 37 | String value() default ""; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/SingleThreaded.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.annotation; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Annotation to document that a class is intended to be used in a single-threaded context. 28 | * Classes marked with this annotation are not designed for concurrent access and should 29 | * be accessed by only one thread at a time. 30 | *

31 | * Created by Peter Lawrey on 18/05/2015. 32 | */ 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Target(ElementType.TYPE) 35 | public @interface SingleThreaded { 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/UsedViaReflection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.annotation; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | import static java.lang.annotation.ElementType.*; 26 | import static java.lang.annotation.RetentionPolicy.CLASS; 27 | 28 | /** 29 | * Annotation to indicate that the annotated member is accessed via reflection, or 30 | * that it must be public for tests to work. This annotation can be used as a marker 31 | * to prevent accidental removal or modification of elements that are used dynamically. 32 | */ 33 | @Documented 34 | @Retention(CLASS) 35 | @Target({METHOD, FIELD, CONSTRUCTOR, TYPE}) 36 | public @interface UsedViaReflection { 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides annotations for specifying and documenting constraints, expected behavior, and 3 | * meta-information for elements within the Chronicle Core library. 4 | *

5 | * The annotations in this package can be used for a range of purposes such as: 6 | *

12 | *

13 | * Examples of annotations provided in this package include: 14 | *

20 | *

21 | * These annotations may be used to convey intentions, constraints, and additional information 22 | * about elements in the codebase which can be beneficial for documentation, analysis or runtime behavior. 23 | */ 24 | package net.openhft.chronicle.core.annotation; 25 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/announcer/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides functionality for libraries to announce themselves along with useful information. 3 | * 4 | *

The {@link net.openhft.chronicle.core.announcer.Announcer} class contains static methods that libraries 5 | * can use to announce themselves. It prints information related to the artifact and the JVM. This 6 | * information can include the group ID and artifact ID of the library, and additional properties 7 | * that provide useful context or data. 8 | * 9 | *

Announcements can be turned off by setting the system property "chronicle.announcer.disable" to true. 10 | * This feature might be used for debugging or reducing console output. 11 | * 12 | *

This package is part of the Chronicle Core library which provides utilities and low-level support 13 | * for higher-level components. 14 | * 15 | * @see net.openhft.chronicle.core.announcer.Announcer 16 | */ 17 | package net.openhft.chronicle.core.announcer; 18 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/cleaner/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides utility classes and interfaces to efficiently manage the cleanup of byte buffers. 3 | * 4 | *

This package includes a {@link net.openhft.chronicle.core.cleaner.CleanerServiceLocator} 5 | * that locates an appropriate implementation of {@link net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService} 6 | * which can be used to clean DirectByteBuffers. This is especially useful for preventing memory leaks in 7 | * environments where direct memory is allocated outside of the Java heap. 8 | * 9 | *

The {@link net.openhft.chronicle.core.cleaner.CleanerServiceLocator} uses the Java ServiceLoader mechanism 10 | * to find implementations of {@link net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService}, 11 | * which is an interface that can be implemented to provide custom buffer cleaning strategies. 12 | * 13 | * @see net.openhft.chronicle.core.cleaner.CleanerServiceLocator 14 | * @see net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService 15 | */ 16 | package net.openhft.chronicle.core.cleaner; 17 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/cleaner/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides a service provider interface (SPI) for ByteBuffer cleaning operations. 3 | * 4 | *

This package contains an interface, {@link net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService}, 5 | * that defines the contract for cleaning memory resources associated with ByteBuffers. 6 | * This is particularly useful for direct ByteBuffers, where the memory is allocated outside 7 | * the regular heap and manual intervention is sometimes necessary to release resources. 8 | * 9 | *

Clients can use different implementations of ByteBufferCleanerService based on their 10 | * specific needs or constraints. Implementations can be provided by third-party libraries or custom 11 | * solutions. The impact level of the cleaning operation is also specified, helping clients make informed 12 | * decisions based on performance or resource considerations. 13 | * 14 | *

This package is part of the Chronicle Core library, which provides a set of low-level utilities 15 | * for high-performance systems. 16 | * 17 | * @see net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService 18 | */ 19 | package net.openhft.chronicle.core.cleaner.spi; 20 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/cooler/CpuCooler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.cooler; 19 | 20 | /** 21 | * This interface represents a CPU cooler and provides a method to perform some operation that will 22 | * "disturb" the CPU, i.e., cause it to perform some work. 23 | */ 24 | public interface CpuCooler { 25 | /** 26 | * Performs an operation that "disturbs" the CPU, causing it to do some work. 27 | */ 28 | void disturb(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/cooler/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides classes for testing the effectiveness of various CPU cooling strategies. 3 | * 4 | *

This package contains the {@link net.openhft.chronicle.core.cooler.CoolerTester} class 5 | * which is designed to assess the performance of different {@link net.openhft.chronicle.core.cooler.CpuCooler} 6 | * implementations. This is achieved by configuring and executing various tests using multiple cooling strategies, 7 | * and recording the time taken for each test to complete. 8 | * 9 | *

The {@link net.openhft.chronicle.core.cooler.CpuCooler} interface represents a CPU cooler 10 | * and provides a method to perform operations that cause the CPU to perform some work, effectively "disturbing" it. 11 | * 12 | *

The {@link net.openhft.chronicle.core.cooler.CpuCoolers} enum contains various CPU cooler implementations, 13 | * each employing a different strategy to disturb the CPU. The specific disturbance strategy is defined by the 14 | * {@code disturb()} method of each enum constant. 15 | * 16 | * @see net.openhft.chronicle.core.cooler.CoolerTester 17 | * @see net.openhft.chronicle.core.cooler.CpuCooler 18 | * @see net.openhft.chronicle.core.cooler.CpuCoolers 19 | */ 20 | package net.openhft.chronicle.core.cooler; 21 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/domestic/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package and any and all sub-packages contains strictly internal classes reserved for Chronicle Software. 21 | * Domestic classes shall never be used directly by end-user code. Instead, they are only available 22 | * for use internally by other Chronicle libraries. 23 | *

24 | * Specifically, the following actions (including, but not limited to) are not allowed 25 | * on internal classes and packages: 26 | *

31 | *

32 | * The classes in this package and any sub-package are subject to change at any time for any reason. 33 | */ 34 | package net.openhft.chronicle.core.domestic; 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/internal/ChronicleGuarding.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.internal; 2 | 3 | public class ChronicleGuarding { 4 | 5 | @SuppressWarnings("EmptyMethod") 6 | public static void bootstrap() { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/internal/analytics/MuteAnalytics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.internal.analytics; 20 | 21 | import net.openhft.chronicle.core.analytics.AnalyticsFacade; 22 | import org.jetbrains.annotations.NotNull; 23 | 24 | import java.util.Map; 25 | 26 | import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; 27 | 28 | enum MuteAnalytics implements AnalyticsFacade { 29 | 30 | INSTANCE; 31 | 32 | // Used for testing only 33 | int invocationCounter; 34 | 35 | @Override 36 | public void sendEvent(@NotNull String name, @NotNull Map additionalEventParameters) { 37 | requireNonNull(name); 38 | requireNonNull(additionalEventParameters); 39 | 40 | // Ignore the call as this instance is mute 41 | invocationCounter++; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/internal/analytics/ReflectiveAnalytics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.internal.analytics; 20 | 21 | import net.openhft.chronicle.core.analytics.AnalyticsFacade; 22 | import org.jetbrains.annotations.NotNull; 23 | 24 | import java.lang.reflect.Method; 25 | import java.util.Map; 26 | 27 | import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; 28 | 29 | final class ReflectiveAnalytics implements AnalyticsFacade { 30 | 31 | private static final String CLASS_NAME = "net.openhft.chronicle.analytics.Analytics"; 32 | 33 | private final Object delegate; 34 | 35 | public ReflectiveAnalytics(@NotNull final Object delegate) { 36 | this.delegate = requireNonNull(delegate); 37 | } 38 | 39 | @Override 40 | public void sendEvent(@NotNull final String name, @NotNull final Map additionalEventParameters) { 41 | requireNonNull(name); 42 | requireNonNull(additionalEventParameters); 43 | final Method m = ReflectionUtil.methodOrThrow(CLASS_NAME, "sendEvent", String.class, Map.class); 44 | ReflectionUtil.invokeOrThrow(m, delegate, name, additionalEventParameters); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * This package and any and all sub-packages contains strictly internal classes for this Chronicle library. 21 | * Internal classes shall never be used directly. 22 | *

23 | * Specifically, the following actions (including, but not limited to) are not allowed 24 | * on internal classes and packages: 25 | *

30 | *

31 | * The classes in this package and any sub-package are subject to 32 | * changes at any time for any reason. 33 | */ 34 | package net.openhft.chronicle.core.internal; 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/internal/util/MapUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.internal.util; 20 | 21 | import net.openhft.chronicle.core.util.ObjectUtils; 22 | import org.jetbrains.annotations.NotNull; 23 | 24 | import java.util.AbstractMap; 25 | import java.util.Collections; 26 | import java.util.Map; 27 | import java.util.stream.Stream; 28 | 29 | import static java.util.stream.Collectors.collectingAndThen; 30 | import static java.util.stream.Collectors.toMap; 31 | import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; 32 | 33 | public final class MapUtil { 34 | 35 | private MapUtil() { 36 | } 37 | 38 | public static Map.Entry entry(@NotNull final K key, @NotNull final V value) { 39 | requireNonNull(key); 40 | requireNonNull(value); 41 | return new AbstractMap.SimpleImmutableEntry<>(key, value); 42 | } 43 | 44 | @SuppressWarnings("varargs") 45 | @SafeVarargs 46 | public static Map ofUnmodifiable(final Map.Entry... entries) { 47 | requireNonNull(entries); 48 | return Stream.of(entries) 49 | .map(ObjectUtils::requireNonNull) 50 | .collect(collectingAndThen(toMap(Map.Entry::getKey, Map.Entry::getValue), Collections::unmodifiableMap)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/internal/util/NopThreadConfinementAsserter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.internal.util; 20 | 21 | import net.openhft.chronicle.core.util.ThreadConfinementAsserter; 22 | 23 | enum NopThreadConfinementAsserter implements ThreadConfinementAsserter { 24 | INSTANCE; 25 | 26 | @Override 27 | public void assertThreadConfined() { 28 | // Do nothing 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/internal/util/RangeUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.internal.util; 20 | 21 | public final class RangeUtil { 22 | 23 | private RangeUtil() {} 24 | 25 | public static final String IS_POSITIVE = " is positive."; 26 | public static final String IS_NEGATIVE = " is negative."; 27 | public static final String IS_ZERO = " is zero."; 28 | public static final String IS_EQUAL_TO = " is equal to."; 29 | public static final String IS_NOT_POSITIVE = " is not positive."; 30 | public static final String IS_NOT_NEGATIVE = " is not negative."; 31 | public static final String IS_NOT_ZERO = " is not zero."; 32 | public static final String IS_NOT_EQUAL_TO = " is not equal to "; 33 | public static final String IS_NOT_IN_THE_RANGE = " is not in the range ["; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/internal/util/ThreadConfinementLifecycle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.internal.util; 20 | 21 | import net.openhft.chronicle.core.util.ThreadConfinementAsserter; 22 | 23 | import java.util.concurrent.atomic.AtomicBoolean; 24 | 25 | public final class ThreadConfinementLifecycle { 26 | 27 | private static final boolean ASSERTIONS_ENABLE = assertionsEnable(); 28 | 29 | private ThreadConfinementLifecycle() {} 30 | 31 | public static ThreadConfinementAsserter create() { 32 | return create(ASSERTIONS_ENABLE); 33 | } 34 | 35 | public static ThreadConfinementAsserter createEnabled() { 36 | return create(true); 37 | } 38 | 39 | static ThreadConfinementAsserter create(boolean active) { 40 | return active 41 | ? new VanillaThreadConfinementAsserter() 42 | : NopThreadConfinementAsserter.INSTANCE; 43 | } 44 | 45 | static boolean assertionsEnable() { 46 | final AtomicBoolean ae = new AtomicBoolean(); 47 | assert testAssert(ae); 48 | return ae.get(); 49 | } 50 | 51 | private static boolean testAssert(final AtomicBoolean ae) { 52 | ae.set(true); 53 | return true; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/internal/util/VanillaThreadConfinementAsserter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.internal.util; 20 | 21 | import net.openhft.chronicle.core.util.ThreadConfinementAsserter; 22 | 23 | class VanillaThreadConfinementAsserter implements ThreadConfinementAsserter { 24 | 25 | private volatile Thread initialThread; 26 | 27 | @Override 28 | public void assertThreadConfined() { 29 | final Thread current = Thread.currentThread(); 30 | Thread past = initialThread; 31 | if (past == null) { 32 | synchronized (this) { 33 | if (initialThread == null) { 34 | initialThread = current; 35 | } 36 | } 37 | past = current; 38 | } 39 | if (past != current) { 40 | throw new IllegalStateException("Thread " + current + " accessed a thread confined class that was already accessed by thread " + initialThread); 41 | } 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "VanillaThreadConfinementAsserter{" + 47 | "initialThread=" + initialThread + 48 | '}'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/io/CleaningRandomAccessFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | package net.openhft.chronicle.core.io; 21 | 22 | import java.io.File; 23 | import java.io.FileNotFoundException; 24 | import java.io.RandomAccessFile; 25 | 26 | /** 27 | * A RandomAccessFile must be explicitly close or cause a resources leak. 28 | *

29 | * Weak references RAF can result in a resource leak when GC'ed which doesn't appear if the GC isn't running. 30 | */ 31 | public class CleaningRandomAccessFile extends RandomAccessFile { 32 | public CleaningRandomAccessFile(String name, String mode) throws FileNotFoundException { 33 | super(name, mode); 34 | } 35 | 36 | public CleaningRandomAccessFile(File file, String mode) throws FileNotFoundException { 37 | super(file, mode); 38 | } 39 | 40 | @SuppressWarnings({"deprecation", "removal"}) 41 | @Override 42 | protected void finalize() throws Throwable { 43 | super.finalize(); 44 | Closeable.closeQuietly(this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/io/ClosedState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | package net.openhft.chronicle.core.io; 21 | /** 22 | * Functional interface representing a closed state. 23 | * This interface provides a method to check if an object is in a closed state. 24 | */ 25 | @FunctionalInterface 26 | public interface ClosedState { 27 | 28 | /** 29 | * Checks if the object is in a closed state. 30 | * 31 | * @return true if the object is closed, false otherwise. 32 | */ 33 | boolean isClosed(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/io/MonitorReferenceCounted.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.io; 20 | /** 21 | * This interface extends {@link ReferenceCountedTracer} and provides methods for monitoring the reference counted object. 22 | */ 23 | public interface MonitorReferenceCounted extends ReferenceCountedTracer { 24 | 25 | /** 26 | * Sets the monitored state of the object. 27 | * 28 | * @param unmonitored {@code true} to set the object as unmonitored, {@code false} to set it as monitored. 29 | */ 30 | void unmonitored(boolean unmonitored); 31 | 32 | /** 33 | * @return {@code true} if the object is unmonitored, {@code false} if it is monitored. 34 | */ 35 | boolean unmonitored(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/io/Monitorable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.io; 20 | 21 | /** 22 | * Interface for objects that can be monitored and unmonitored. 23 | *

24 | * This is useful for managing resources that need to be tracked and potentially cleaned up 25 | * when they are no longer needed. 26 | */ 27 | public interface Monitorable { 28 | 29 | /** 30 | * Stops monitoring the resource. 31 | *

32 | * Implementations of this method should ensure that the resource and any resources it uses 33 | * are no longer being tracked for any purpose such as cleanup, resource management, or debugging. 34 | * This is particularly important for resources that are explicitly managed to avoid leaks. 35 | */ 36 | void unmonitor(); 37 | 38 | /** 39 | * Stops the monitoring of the specified object. 40 | * 41 | * @param t The object to stop monitoring 42 | */ 43 | static void unmonitor(final Object t) { 44 | if (t instanceof Monitorable) 45 | ((Monitorable) t).unmonitor(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/io/QueryCloseable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 chronicle.software 3 | */ 4 | 5 | package net.openhft.chronicle.core.io; 6 | /** 7 | * An interface for querying the closeable state of an object. 8 | * Provides methods to check if the object is closed or in the process of closing. 9 | */ 10 | public interface QueryCloseable { 11 | 12 | /** 13 | * Checks if this object is in the process of closing. 14 | *

15 | * This method should always return true if {@link #isClosed()} returns true. 16 | * 17 | * @return true if the {@code close()} method has been called (but not necessarily completed) 18 | */ 19 | default boolean isClosing() { 20 | return isClosed(); 21 | } 22 | 23 | /** 24 | * Checks if this object is closed. 25 | * 26 | * @return true if the {@code close()} method has completed, false otherwise 27 | */ 28 | boolean isClosed(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/io/Resettable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.io; 19 | 20 | /** 21 | * An interface representing a DTO (Data Transfer Object) or component that can be reset to its initial state. 22 | * Implementations of this interface provide a {@code reset()} method to reset the state of the object. 23 | */ 24 | public interface Resettable { 25 | /** 26 | * Resets the state of the object to its initial state. 27 | * Implementations should restore the object's internal fields or properties 28 | * to their default values or the values set during initialization. 29 | */ 30 | void reset(); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/io/Syncable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.io; 20 | 21 | /** 22 | * An interface for objects that can be synced to underlying media if supported. 23 | * Implementations can perform a sync operation to ensure data is flushed to the underlying media. 24 | */ 25 | public interface Syncable { 26 | 27 | /** 28 | * Performs a sync operation if the given object implements the {@code Syncable} interface. 29 | * This method provides a convenient way to invoke the sync operation on an object without explicitly checking its type. 30 | * 31 | * @param o The object to sync, if it implements the {@code Syncable} interface. 32 | */ 33 | static void syncIfAvailable(Object o) { 34 | if (o instanceof Syncable) 35 | ((Syncable) o).sync(); 36 | } 37 | 38 | /** 39 | * Performs a sync operation up to the point that this handle has read or written. 40 | * The behavior of this method depends on whether syncing is supported and the underlying implementation. 41 | * There might be data beyond this point that isn't synced. 42 | * It may not perform any action if syncing is not supported or has been turned off through configuration. 43 | */ 44 | void sync(); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/onoes/LogLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | package net.openhft.chronicle.core.onoes; 21 | 22 | /** 23 | * LogLevel is an enumeration that defines various levels of logging within an application. 24 | * These levels allow for granularity and control over what types of messages should be logged. 25 | * 26 | *

32 | */ 33 | public enum LogLevel { 34 | ERROR, 35 | WARN, 36 | PERF, 37 | DEBUG 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/onoes/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides classes and interfaces for exception handling, logging, and associated utilities. 3 | *

4 | * This package contains classes and interfaces that enable handling exceptions 5 | * in a uniform manner throughout an application. This includes mechanisms for 6 | * chaining multiple exception handlers together, logging exceptions, handling 7 | * exceptions on a per-thread basis, and recording exceptions. 8 | * 9 | *

10 | * The core of this package is the {@link net.openhft.chronicle.core.onoes.ExceptionHandler} 11 | * interface which allows for custom logic to be defined for handling different 12 | * types of exceptions. 13 | * 14 | *

15 | * Other classes and enumerations within the package include: 16 | * 17 | *

26 | *

27 | * This package is part of the Chronicle-Core library by OpenHFT. 28 | * 29 | * 30 | * @see net.openhft.chronicle.core.onoes.ExceptionHandler 31 | */ 32 | package net.openhft.chronicle.core.onoes; 33 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/scoped/AbstractScopedResource.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.scoped; 2 | 3 | import org.jetbrains.annotations.Nullable; 4 | 5 | abstract class AbstractScopedResource implements ScopedResource { 6 | 7 | private final long createdTimeNanos; 8 | private final ScopedThreadLocal scopedThreadLocal; 9 | 10 | protected AbstractScopedResource(ScopedThreadLocal scopedThreadLocal) { 11 | this.scopedThreadLocal = scopedThreadLocal; 12 | this.createdTimeNanos = System.nanoTime(); 13 | } 14 | 15 | @Override 16 | public void close() { 17 | scopedThreadLocal.returnResource(this); 18 | } 19 | 20 | /** 21 | * Do anything that needs to be done before returning a resource to a caller 22 | */ 23 | void preAcquire() { 24 | // Do nothing by default 25 | } 26 | 27 | /** 28 | * Close the contained resource and clear any references 29 | */ 30 | abstract void closeResource(); 31 | 32 | /** 33 | * The time this resource was created 34 | * 35 | * @return the {@link System#nanoTime()} of creation 36 | */ 37 | public long getCreatedTimeNanos() { 38 | return createdTimeNanos; 39 | } 40 | 41 | /** 42 | * Get the type of object contained, may return null 43 | * 44 | * @return the type of object contained, or null if it can't be determined 45 | */ 46 | @Nullable 47 | public abstract Class getType(); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/scoped/ScopedResource.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.scoped; 2 | 3 | import java.io.Closeable; 4 | 5 | /** 6 | * A scoped resource, it is drawn from a "pool" of sorts, and will be returned 7 | * to that pool when {@link #close()} is called. 8 | *

9 | * Do not keep a reference to the contained resource beyond the scope. 10 | * 11 | * @param The type of the resource contained 12 | */ 13 | public interface ScopedResource extends Closeable { 14 | 15 | /** 16 | * Get the contained resource 17 | * 18 | * @return The resource 19 | */ 20 | T get(); 21 | 22 | /** 23 | * Signifies the end of the scope, will return the resource to the "pool" for use by other acquirers 24 | */ 25 | @Override 26 | void close(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/scoped/ScopedResourcePool.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.scoped; 2 | 3 | /** 4 | * A pool of resources, whereby a lease is taken on an instance 5 | * by calling {@link #get()} and that lease is relinquished when 6 | * {@link ScopedResource#close()} is called. 7 | *

8 | * Example of use: 9 | *

{@code
10 |  *   try (ScopedResource sharedWire = sharedWireScopedThreadLocal.get()) {
11 |  *     Wire wire = sharedWire.get();
12 |  *     // ... do something with the wire
13 |  *   } // it is returned for use by inner scopes here
14 |  * }
15 | * 16 | * @param The type of object contained in the pool 17 | */ 18 | public interface ScopedResourcePool { 19 | 20 | /** 21 | * Get a scoped instance of the shared resource 22 | * 23 | * @return the {@link ScopedResource}, to be closed once it is finished being used 24 | */ 25 | ScopedResource get(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/scoped/StrongReferenceScopedResource.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.scoped; 2 | 3 | import static net.openhft.chronicle.core.io.Closeable.closeQuietly; 4 | 5 | /** 6 | * A {@link ScopedResource} that will always retain a strong reference to the 7 | * contained resource, even when not "in use" 8 | * 9 | * @param The type of the contained resource 10 | */ 11 | public class StrongReferenceScopedResource extends AbstractScopedResource { 12 | 13 | private final T resource; 14 | 15 | StrongReferenceScopedResource(ScopedThreadLocal scopedThreadLocal, T resource) { 16 | super(scopedThreadLocal); 17 | this.resource = resource; 18 | } 19 | 20 | public T get() { 21 | return resource; 22 | } 23 | 24 | @Override 25 | public void closeResource() { 26 | closeQuietly(resource); 27 | } 28 | 29 | @Override 30 | public Class getType() { 31 | return resource.getClass(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/shutdown/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides classes and interfaces for handling shutdown procedures in a controlled manner. 3 | * 4 | *

This package includes classes for registering shutdown hooks with specific priorities, allowing for 5 | * an orderly shutdown of resources. This is particularly useful in scenarios where resources need to 6 | * be released or cleaned up in a specific order during the JVM shutdown phase. 7 | * 8 | *

Example usage: 9 | *

10 |  * {@code
11 |  *     // Register a hook to be executed at priority 50.
12 |  *     PriorityHook.add(50, () -> {
13 |  *         // Code to execute during shutdown.
14 |  *     });
15 |  * }
16 |  * 
17 | * 18 | * @see net.openhft.chronicle.core.shutdown.Hooklet 19 | * @see net.openhft.chronicle.core.shutdown.PriorityHook 20 | */ 21 | package net.openhft.chronicle.core.shutdown; 22 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Core/91a2db2ec698cb45e9133f529c79d13815349edc/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/BooleanConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.util; 19 | 20 | /** 21 | * Represents an operation that accepts a single {@code Boolean}-valued argument and returns no result. This is the 22 | * primitive type specialization of {@link java.util.function.Consumer} for {@code Boolean}. Unlike most other functional 23 | * interfaces, {@code BooleanConsumer} is expected to operate via side-effects. 24 | *

This is a functional interface whose functional method is 25 | * {@link #accept(Boolean)}. 26 | * 27 | * @see java.util.function.Consumer 28 | */ 29 | @FunctionalInterface 30 | public interface BooleanConsumer { 31 | 32 | /** 33 | * Performs this operation on the given argument. 34 | * 35 | * @param value the input argument 36 | */ 37 | void accept(Boolean value); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ByteConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.util; 19 | 20 | /** 21 | * Represents an operation that accepts a single {@code byte}-valued argument and returns no result. This is the 22 | * primitive type specialization of {@link java.util.function.Consumer} for {@code byte}. Unlike most other functional 23 | * interfaces, {@code ByteConsumer} is expected to operate via side effects. 24 | *

This is a functional interface whose functional method is {@link 25 | * #accept(byte)}. 26 | * 27 | * @see java.util.function.Consumer 28 | * @since 1.8 29 | */ 30 | @FunctionalInterface 31 | public interface ByteConsumer { 32 | 33 | /** 34 | * Performs this operation on the given argument. 35 | * 36 | * @param value the input argument 37 | */ 38 | void accept(byte value); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/CharConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.util; 19 | 20 | /** 21 | * Represents an operation that accepts a single {@code char}-valued argument and returns no result. This is the 22 | * primitive type specialization of {@link java.util.function.Consumer} for {@code char}. Unlike most other functional 23 | * interfaces, {@code CharConsumer} is expected to operate via side effects. 24 | *

This is a functional interface whose functional method is {@link 25 | * #accept(char)}. 26 | * 27 | * @see java.util.function.Consumer 28 | * @since 1.8 29 | */ 30 | @FunctionalInterface 31 | public interface CharConsumer { 32 | 33 | /** 34 | * Performs this operation on the given argument. 35 | * 36 | * @param value the input argument 37 | */ 38 | void accept(char value); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/CharToBooleanFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.util; 19 | 20 | /** 21 | * Represents a function that accepts a single {@code char} value argument and produces a 22 | * {@code boolean} result. This is the {@code char}-consuming primitive type specialization of 23 | * {@code Function}. 24 | * 25 | *

This is a functional interface whose functional method is {@link #applyAsChar(char)}. 26 | * 27 | * @see java.util.function.Function 28 | */ 29 | @FunctionalInterface 30 | public interface CharToBooleanFunction { 31 | 32 | /** 33 | * Applies this function to the given {@code char} value. 34 | * 35 | * @param value the {@code char} value to be processed by the function. 36 | * @return the {@code boolean} result of the function. 37 | */ 38 | boolean applyAsChar(char value); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ClassLocal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | import java.util.function.Function; 24 | 25 | /** 26 | * Lambda friendly, ClassLocal value to cache information relating to a class. 27 | * 28 | * @param the type of value in this ClassLocal 29 | */ 30 | public class ClassLocal extends ClassValue { 31 | private final Function, V> classVFunction; 32 | 33 | private ClassLocal(Function, V> classVFunction) { 34 | this.classVFunction = classVFunction; 35 | } 36 | 37 | /** 38 | * Function to create a value to cache information associated with a Class 39 | * 40 | * @param classVFunction to generate the associated value. 41 | * @param the type of value in this ClassLocal 42 | * @return the ClassLocal 43 | */ 44 | @NotNull 45 | public static ClassLocal withInitial(Function, V> classVFunction) { 46 | return new ClassLocal<>(classVFunction); 47 | } 48 | 49 | /** 50 | * WARNING Do not call this directly 51 | */ 52 | @Override 53 | protected V computeValue(Class type) { 54 | return classVFunction.apply(type); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/FloatConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.util; 19 | 20 | /** 21 | * Represents an operation that accepts a single {@code float}-valued argument and returns no result. This is the 22 | * primitive type specialization of {@link java.util.function.Consumer} for {@code float}. Unlike most other functional 23 | * interfaces, {@code FloatConsumer} is expected to operate via side effects. 24 | *

This is a functional interface whose functional method is {@link 25 | * #accept(float)}. 26 | * 27 | * @see java.util.function.Consumer 28 | * @since 1.8 29 | */ 30 | @FunctionalInterface 31 | public interface FloatConsumer { 32 | 33 | /** 34 | * Performs this operation on the given argument. 35 | * 36 | * @param value the input argument 37 | */ 38 | void accept(float value); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/IgnoresEverything.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | /** 22 | * A marker interface which shows this implementation ignores everything. 23 | *

24 | * A caller can assume it doesn't need to call this. 25 | *

26 | * Used by {@link Mocker#ignored(java.lang.Class, java.lang.Class[])} 27 | */ 28 | public interface IgnoresEverything { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/MisAlignedAssertionError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.util; 19 | 20 | /** 21 | * The {@code MisAlignedAssertionError} is thrown to indicate that an attempted memory operation 22 | * failed due to a misaligned memory address. 23 | *

24 | * This error typically indicates a programming error in low-level memory manipulation. 25 | * For example, it is thrown by methods like {@code compareAndSwapInt} when the memory 26 | * address provided for a compare-and-swap operation is not properly aligned according 27 | * to the requirements of the underlying architecture or API. 28 | * 29 | *

30 | * As this error is an {@code AssertionError}, it is considered as an unchecked error. 31 | * 32 | * 33 | * @see AssertionError 34 | */ 35 | public class MisAlignedAssertionError extends AssertionError { 36 | private static final long serialVersionUID = 0L; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ObjBooleanConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | /** 22 | * Represents an operation that accepts an object-valued and {@code Boolean}-valued argument, and returns no result. This is the 23 | * {@code (reference, long)} specialization of {@link java.util.function.BiConsumer} for {@code Boolean}. Unlike most other functional 24 | * interfaces, {@code ObjBooleanConsumer} is expected to operate via side effects. 25 | *

This is a functional interface whose functional method is 26 | * {@link #accept(Object, Boolean)}. 27 | * 28 | * @see java.util.function.BiConsumer 29 | */ 30 | @FunctionalInterface 31 | public interface ObjBooleanConsumer { 32 | 33 | /** 34 | * Performs this operation on the given arguments. 35 | * 36 | * @param t the first input argument 37 | * @param value the second input argument 38 | */ 39 | void accept(T t, Boolean value); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ObjByteConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | /** 22 | * Represents an operation that accepts an object-valued and {@code byte}-valued argument, and returns no result. This is the 23 | * {@code (reference, long)} specialization of {@link java.util.function.BiConsumer} for {@code byte}. Unlike most other functional 24 | * interfaces, {@code ObjByteConsumer} is expected to operate via side effects. 25 | *

This is a functional interface whose functional method is 26 | * {@link #accept(Object, byte)}. 27 | * 28 | * @see java.util.function.BiConsumer 29 | */ 30 | @FunctionalInterface 31 | public interface ObjByteConsumer { 32 | 33 | /** 34 | * Performs this operation on the given arguments. 35 | * 36 | * @param t the first input argument 37 | * @param value the second input argument 38 | */ 39 | void accept(T t, byte value); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ObjCharConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | /** 22 | * Represents an operation that accepts an object-valued and {@code char}-valued argument, and returns no result. This is the 23 | * {@code (reference, long)} specialization of {@link java.util.function.BiConsumer} for {@code char}. Unlike most other functional 24 | * interfaces, {@code ObjCharConsumer} is expected to operate via side effects. 25 | *

This is a functional interface whose functional method is 26 | * {@link #accept(Object, char)}. 27 | * 28 | * @see java.util.function.BiConsumer 29 | */ 30 | @FunctionalInterface 31 | public interface ObjCharConsumer { 32 | 33 | /** 34 | * Performs this operation on the given arguments. 35 | * 36 | * @param t the first input argument 37 | * @param value the second input argument 38 | */ 39 | void accept(T t, char value); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ObjFloatConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | /** 22 | * Represents an operation that accepts a an object-valued and {@code float}-valued argument, and returns no result. This is the 23 | * {@code (reference, long)} specialization of {@link java.util.function.BiConsumer} for {@code float}. Unlike most other functional 24 | * interfaces, {@code ObjFloatConsumer} is expected to operate via side-effects. 25 | *

26 | * This is a functional interface whose functional method is 27 | * {@link #accept(Object, float)}. 28 | * 29 | * @see java.util.function.BiConsumer 30 | */ 31 | @FunctionalInterface 32 | public interface ObjFloatConsumer { 33 | 34 | /** 35 | * Performs this operation on the given arguments. 36 | * 37 | * @param t the first input argument 38 | * @param value the second input argument 39 | */ 40 | void accept(T t, float value); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ObjShortConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | /** 22 | * Represents an operation that accepts a an object-valued and {@code short}-valued argument, and returns no result. This is the 23 | * {@code (reference, long)} specialization of {@link java.util.function.BiConsumer} for {@code short}. Unlike most other functional 24 | * interfaces, {@code ObjShortConsumer} is expected to operate via side-effects. 25 | *

26 | * This is a functional interface whose functional method is 27 | * {@link #accept(Object, short)}. 28 | * 29 | * @see java.util.function.BiConsumer 30 | */ 31 | @FunctionalInterface 32 | public interface ObjShortConsumer { 33 | 34 | /** 35 | * Performs this operation on the given arguments. 36 | * 37 | * @param t the first input argument 38 | * @param value the second input argument 39 | */ 40 | void accept(T t, short value); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/SerializableBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import java.io.Serializable; 22 | import java.util.function.BiFunction; 23 | 24 | /** 25 | * This interface is a Function which is also Serializable. 26 | */ 27 | @FunctionalInterface 28 | public interface SerializableBiFunction extends BiFunction, Serializable { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/SerializableConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import java.io.Serializable; 22 | import java.util.function.Consumer; 23 | 24 | @FunctionalInterface 25 | public interface SerializableConsumer extends Consumer, Serializable { 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/SerializableFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import java.io.Serializable; 22 | import java.util.function.Function; 23 | 24 | /** 25 | * This interface is a Function which is also Serializable. 26 | */ 27 | @FunctionalInterface 28 | public interface SerializableFunction extends Function, Serializable { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/SerializablePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import java.io.Serializable; 22 | import java.util.function.Predicate; 23 | 24 | @FunctionalInterface 25 | public interface SerializablePredicate extends Predicate, Serializable { 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/SerializableUpdater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * This interface expect to take an object for alteration and it must be serializable. 25 | */ 26 | @FunctionalInterface 27 | public interface SerializableUpdater extends Updater, Serializable { 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/SerializableUpdaterWithArg.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * This interface expect to take an object for alteration and it must be serializable. 25 | */ 26 | @FunctionalInterface 27 | public interface SerializableUpdaterWithArg extends Serializable { 28 | void accept(U updated, A argument); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ShortConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.util; 19 | 20 | /** 21 | * Represents an operation that accepts a single {@code short}-valued argument and returns no result. This is the 22 | * primitive type specialization of {@link java.util.function.Consumer} for {@code short}. Unlike most other functional 23 | * interfaces, {@code ShortConsumer} is expected to operate via side-effects. 24 | *

This is a functional interface whose functional method is {@link 25 | * #accept(short)}. 26 | * 27 | * @see java.util.function.Consumer 28 | * @since 1.8 29 | */ 30 | @FunctionalInterface 31 | public interface ShortConsumer { 32 | 33 | /** 34 | * Performs this operation on the given argument. 35 | * 36 | * @param value the input argument 37 | */ 38 | void accept(short value); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/SimpleCleaner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; 22 | 23 | public class SimpleCleaner { 24 | private static final AtomicIntegerFieldUpdater CLEANED_FLAG = 25 | AtomicIntegerFieldUpdater.newUpdater(SimpleCleaner.class, "cleaned"); 26 | 27 | private final Runnable thunk; 28 | @SuppressWarnings("unused") 29 | private volatile int cleaned = 0; 30 | 31 | public SimpleCleaner(Runnable thunk) { 32 | this.thunk = thunk; 33 | } 34 | 35 | public void clean() { 36 | if (CLEANED_FLAG.compareAndSet(this, 0, 1)) 37 | thunk.run(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThreadConfinementAsserter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import net.openhft.chronicle.core.internal.util.ThreadConfinementLifecycle; 22 | 23 | public interface ThreadConfinementAsserter { 24 | 25 | /** 26 | * Asserts that this thread is the only thread that has ever called this 27 | * method. 28 | * 29 | * @throws IllegalStateException If another thread called this method previously. 30 | */ 31 | void assertThreadConfined(); 32 | 33 | /** 34 | * Creates and returns a new ThreadConfinementAsserter if assertions are enabled, otherwise 35 | * returns a no-op asserter. 36 | * 37 | * @return Creates and returns a new ThreadConfinementAsserter if assertions are enabled, otherwise 38 | * returns a no-op asserter 39 | */ 40 | static ThreadConfinementAsserter create() { 41 | return ThreadConfinementLifecycle.create(); 42 | } 43 | 44 | /** 45 | * Creates and returns a new ThreadConfinementAsserter that is always enabled. 46 | * 47 | * @return Creates and returns a new enabled ThreadConfinementAsserter 48 | */ 49 | static ThreadConfinementAsserter createEnabled() { 50 | return ThreadConfinementLifecycle.createEnabled(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThrowingBiConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import net.openhft.chronicle.core.io.IORuntimeException; 22 | 23 | /** 24 | * Represents an operation that accepts two input arguments and returns no 25 | * result. Unlike most other functional interfaces, {@code ThrowingBiConsumer} is expected 26 | * to operate via side-effects. 27 | *

This is a functional interface 28 | * whose functional method is {@link #accept(Object, Object)}. 29 | * 30 | * @param the type of the input to the function 31 | * @param the type of Throwable thrown 32 | */ 33 | @FunctionalInterface 34 | public interface ThrowingBiConsumer { 35 | 36 | /** 37 | * Performs this operation on the given arguments. 38 | * 39 | * @param in the first input argument 40 | * @param i2 the second input argument 41 | */ 42 | void accept(I in, J i2) throws T, IORuntimeException; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThrowingBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | /** 24 | * Represents a function that accepts two arguments and produces a result. 25 | * This is the two-arity specialization of {@link ThrowingFunction}. 26 | *

27 | * This is a functional interface 28 | * whose functional method is {@link #apply(Object, Object)}. 29 | * 30 | * @param the type of the first argument to the function 31 | * @param the type of the second argument to the function 32 | * @param the type of Throwable thrown 33 | * @param the type of the result of the function 34 | */ 35 | @FunctionalInterface 36 | public interface ThrowingBiFunction { 37 | 38 | /** 39 | * Applies this function to the given arguments. 40 | * 41 | * @param in the first function argument 42 | * @param i2 the second function argument 43 | * @return the function result 44 | * @throws T on an error. 45 | */ 46 | @NotNull 47 | R apply(I in, J i2) throws T; 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThrowingCallable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | package net.openhft.chronicle.core.util; 21 | 22 | import org.jetbrains.annotations.NotNull; 23 | 24 | @FunctionalInterface 25 | public interface ThrowingCallable { 26 | @NotNull 27 | R call() throws T; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThrowingConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | /** 22 | *

23 | * Represents an operation that accepts a single input argument and returns no 24 | * result. Unlike most other functional interfaces, {@code Consumer} is expected 25 | * to operate via side-effects. 26 | *

27 | * This is a functional interface 28 | * whose functional method is {@link #accept(Object)}. 29 | * 30 | * 31 | * @param the type of the input to the function 32 | * @param the type of Throwable thrown 33 | */ 34 | @FunctionalInterface 35 | public interface ThrowingConsumer { 36 | 37 | /** 38 | * Performs this operation on the given argument. 39 | * 40 | * @param in the input argument 41 | */ 42 | void accept(I in) throws T, IllegalStateException; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThrowingConsumerNonCapturing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | /** 22 | * @param the type of the input to the function 23 | * @param the type of Throwable thrown 24 | */ 25 | 26 | public interface ThrowingConsumerNonCapturing { 27 | 28 | /** 29 | * Performs this operation on the given argument. 30 | * 31 | * @param in the input argument 32 | */ 33 | void accept(I in, CharSequence sb, U toBytes) throws T; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThrowingIntSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | package net.openhft.chronicle.core.util; 21 | 22 | /** 23 | *

24 | * Represents a supplier of results which might throw an Exception 25 | *

26 | * There is no requirement that a new or distinct result be returned each 27 | * time the supplier is invoked. 28 | *

29 | * This is a functional interface 30 | * whose functional method is {@link #getAsInt()}. 31 | * 32 | * 33 | * @param the type of exception thrown by this supplier 34 | */ 35 | @FunctionalInterface 36 | public interface ThrowingIntSupplier { 37 | 38 | /** 39 | * Gets a result. 40 | * 41 | * @return a result 42 | */ 43 | int getAsInt() throws T; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThrowingLongSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | package net.openhft.chronicle.core.util; 21 | 22 | /** 23 | *

24 | * Represents a supplier of results which might throw an Exception 25 | *

26 | * There is no requirement that a new or distinct result be returned each 27 | * time the supplier is invoked. 28 | *

29 | * This is a functional longerface 30 | * whose functional method is {@link #getAsLong()}. 31 | * 32 | * 33 | * @param the type of exception thrown by this supplier 34 | */ 35 | @FunctionalInterface 36 | public interface ThrowingLongSupplier { 37 | 38 | /** 39 | * Gets a result. 40 | * 41 | * @return a result 42 | */ 43 | long getAsLong() throws T; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThrowingRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | package net.openhft.chronicle.core.util; 21 | 22 | @FunctionalInterface 23 | public interface ThrowingRunnable { 24 | void run() throws T; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/ThrowingTriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | @FunctionalInterface 24 | public interface ThrowingTriFunction { 25 | 26 | /** 27 | * Applies this function to the given arguments. 28 | * 29 | * @param in the first function argument 30 | * @param i2 the second function argument 31 | * @return the function result 32 | * @throws T on an error. 33 | */ 34 | @NotNull 35 | R apply(I in, J i2, A i3) throws T; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/openhft/chronicle/core/util/Time.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import net.openhft.chronicle.core.time.SystemTimeProvider; 22 | import net.openhft.chronicle.core.time.UniqueMicroTimeProvider; 23 | 24 | /** 25 | * A timer for timeouts which is resilient to pauses in the JVM, tickTime can only increase if the JVM hasn't been paused. 26 | *

27 | * For this to work, currentTimeMillis (or one of the methods that calls it) must be called more frequently than 28 | * every millisecond; the EventLoop implementations in chronicle-threads do this. 29 | * 30 | */ 31 | public final class Time { 32 | private Time() { 33 | } 34 | 35 | public static String uniqueId() { 36 | long l; 37 | try { 38 | l = UniqueMicroTimeProvider.INSTANCE.currentTimeMicros(); 39 | } catch (IllegalStateException e) { 40 | l = SystemTimeProvider.INSTANCE.currentTimeMicros(); 41 | } 42 | return Long.toString(l, 36); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2022 chronicle.software 3 | # 4 | # https://chronicle.software 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | net.openhft.chronicle.core.internal.cleaner.Jdk9ByteBufferCleanerService 20 | net.openhft.chronicle.core.internal.cleaner.ReflectionBasedByteBufferCleanerService 21 | -------------------------------------------------------------------------------- /src/main/resources/net/openhft/chronicle/core/onoes/Google.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 higherfrequencytrading.com 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 | # http://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 or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | 18 | baseUri=https://www.google.co.uk/webhp?sourceid=OpenHFT-ExceptionHandler&ion=1&espv=2&ie=UTF-8#safe=strict&q=java 19 | -------------------------------------------------------------------------------- /src/main/resources/net/openhft/chronicle/core/onoes/Stackoverflow.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 higherfrequencytrading.com 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 | # http://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 or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | 18 | baseUri=http://stackoverflow.com/search?q=%5Bjava%5D 19 | java.lang.NullPointerException=http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it 20 | java.lang.StackOverflowError=http://stackoverflow.com/questions/214741/what-is-a-stackoverflowerror 21 | java.lang.IncompatibleClassChangeError=http://stackoverflow.com/questions/1980452/what-causes-java-lang-incompatibleclasschangeerror 22 | -------------------------------------------------------------------------------- /src/test/java/ClassWithNoPackageTest.java: -------------------------------------------------------------------------------- 1 | import net.openhft.chronicle.core.Jvm; 2 | import org.junit.Test; 3 | 4 | import static org.junit.Assert.assertEquals; 5 | 6 | /** 7 | * This class has no package declaration. 8 | */ 9 | public class ClassWithNoPackageTest { 10 | @Test 11 | public void getPackageName() { 12 | assertEquals("", Jvm.getPackageName(ClassWithNoPackageTest.class)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/ChronicleInitRunnableTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 6 | import static org.mockito.Mockito.*; 7 | import static org.junit.Assert.*; 8 | 9 | public class ChronicleInitRunnableTest { 10 | 11 | @Test 12 | public void testRunMethod() { 13 | ChronicleInitRunnable runnable = mock(ChronicleInitRunnable.class); 14 | runnable.run(); 15 | 16 | // Verify that the run method was called. 17 | verify(runnable, times(1)).run(); 18 | } 19 | 20 | @Test 21 | public void testPostInitDefaultMethod() { 22 | ChronicleInitRunnable runnable = new ChronicleInitRunnable() { 23 | @Override 24 | public void run() { 25 | 26 | } 27 | // No override, use default implementation. 28 | }; 29 | 30 | // Call postInit and verify that it does not throw an exception. 31 | // Since it's a no-op by default, there's no direct result to assert. 32 | assertDoesNotThrow(runnable::postInit); 33 | } 34 | 35 | @Test 36 | public void testOverriddenPostInitMethod() { 37 | ChronicleInitRunnable runnable = new ChronicleInitRunnable() { 38 | @Override 39 | public void run() { 40 | 41 | } 42 | 43 | @Override 44 | public void postInit() { 45 | // Custom implementation for testing. 46 | } 47 | }; 48 | 49 | // Verify that the custom postInit does not throw an exception. 50 | // This is just to confirm that the method can be successfully overridden. 51 | assertDoesNotThrow(runnable::postInit); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/ClassLocalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core; 20 | 21 | import net.openhft.chronicle.core.util.ClassLocal; 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | 26 | public class ClassLocalTest extends CoreTestCommon { 27 | 28 | @Test 29 | public void computeValue() { 30 | long[] count = {0}; 31 | ClassLocal toString = ClassLocal.withInitial(aClass -> { 32 | // System.out.println(aClass); 33 | count[0]++; 34 | return aClass.toGenericString(); 35 | }); 36 | for (int i = 0; i < 1000; i++) { 37 | toString.get(ClassValue.class); 38 | } 39 | assertEquals(1, count[0]); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/JvmMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 chronicle.software 3 | */ 4 | 5 | package net.openhft.chronicle.core; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import static org.junit.Assert.assertTrue; 11 | 12 | public class JvmMain { 13 | static { 14 | System.setProperty("system.properties", "sample.system.properties"); 15 | Jvm.init(); 16 | } 17 | 18 | public static void main(String[] args) { 19 | Logger isDebug = LoggerFactory.getLogger("isDebug"); 20 | assertTrue(!isDebug.isTraceEnabled() && isDebug.isDebugEnabled()); 21 | Logger isInfo = LoggerFactory.getLogger("isInfo"); 22 | assertTrue(!isInfo.isDebugEnabled() && isInfo.isInfoEnabled()); 23 | Logger isWarn = LoggerFactory.getLogger("isWarn"); 24 | assertTrue(!isWarn.isInfoEnabled() && isWarn.isWarnEnabled()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/NotNullIntrumentationTargetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core; 20 | 21 | import org.jetbrains.annotations.NotNull; 22 | import org.junit.Ignore; 23 | import org.junit.Test; 24 | 25 | public class NotNullIntrumentationTargetTest extends CoreTestCommon { 26 | 27 | @Test 28 | public void notNull() { 29 | test("a"); 30 | } 31 | 32 | @Test(expected = NullPointerException.class) 33 | @Ignore("Awaiting https://github.com/osundblad/intellij-annotations-instrumenter-maven-plugin/issues/53. " + 34 | "When compiled by IntelliJ this class is instrumented with null checks but it will throw an IllegalArgumentExceptioj not NPE!") 35 | public void Null() { 36 | test(null); 37 | } 38 | 39 | @SuppressWarnings("EmptyMethod") 40 | private static void test(@NotNull String nn) { 41 | // This should throw an NPE if called with a null argument 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/PerformanceTuningTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenHFT/Chronicle-Core/91a2db2ec698cb45e9133f529c79d13815349edc/src/test/java/net/openhft/chronicle/core/PerformanceTuningTest.java -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/RandomAccessFileCleanupMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 chronicle.software 3 | */ 4 | 5 | package net.openhft.chronicle.core; 6 | 7 | import net.openhft.chronicle.core.io.IOTools; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.io.RandomAccessFile; 12 | import java.nio.ByteBuffer; 13 | 14 | /* 15 | NOTE: RandomAccessFile doesn't clean up it's resources when GC'ed 16 | */ 17 | public class RandomAccessFileCleanupMain { 18 | public static void main(String[] args) throws IOException { 19 | File tempDir = IOTools.createTempFile("RandomAccessFileCleanupMain"); 20 | tempDir.mkdir(); 21 | for (int j = 0; j < 100; j++) { 22 | int files = new File("/proc/self/fd").list().length; 23 | System.out.println("File descriptors " + files); 24 | ByteBuffer bb = ByteBuffer.allocateDirect(64); 25 | for (int i = 0; i < 100; i++) { 26 | // RandomAccessFile file = new CleaningRandomAccessFile(tempDir + "/file" + i, "rw"); 27 | RandomAccessFile file = new RandomAccessFile(tempDir + "/file" + i, "rw"); 28 | bb.clear(); 29 | file.getChannel().write(bb); 30 | } 31 | System.gc(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/ZeroCostAssertionStatusTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core; 20 | 21 | import net.openhft.chronicle.assertions.AssertUtil; 22 | import org.junit.jupiter.api.Test; 23 | 24 | class ZeroCostAssertionStatusTest extends CoreTestCommon { 25 | 26 | @Test 27 | void show() { 28 | boolean ae = false; 29 | try { 30 | assert 0 != 0; 31 | } catch (AssertionError assertionError) { 32 | ae = true; 33 | } 34 | 35 | boolean zcae = false; 36 | try { 37 | assert AssertUtil.SKIP_ASSERTIONS || 0 != 0; 38 | } catch (AssertionError assertionError) { 39 | zcae = true; 40 | } 41 | 42 | System.out.println("Normal assertions are " + (ae ? "ON" : "OFF")); 43 | System.out.println("Zero-cost assertions are " + (zcae ? "ON" : "OFF")); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/annotation/ScopeConfinedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.annotation; 20 | 21 | import net.openhft.chronicle.core.CoreTestCommon; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import java.lang.reflect.Method; 25 | import java.lang.reflect.Type; 26 | import java.util.function.Consumer; 27 | import java.util.stream.Stream; 28 | 29 | import static org.junit.jupiter.api.Assertions.assertEquals; 30 | 31 | class ScopeConfinedTest extends CoreTestCommon { 32 | 33 | @Test 34 | void a() throws NoSuchMethodException { 35 | Method method = Foo.class.getMethod("stream"); 36 | final Type genericReturnType = method.getGenericReturnType(); 37 | 38 | // Not sure how to get the Annotation... 39 | assertEquals("java.util.stream.Stream", genericReturnType.getTypeName()); 40 | } 41 | 42 | interface Foo { 43 | 44 | // Shows and validates the use of the annotation in a parameter 45 | void forEach(Consumer action); 46 | 47 | // Shows and validates the use of the annotation in a return value 48 | Stream<@ScopeConfined T> stream(); 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.announcer; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 6 | import static org.junit.jupiter.api.Assertions.assertThrows; 7 | 8 | class AnnouncerTest { 9 | 10 | @Test 11 | void testAnnounceWithValidArguments() { 12 | // This is a simple test to ensure no exceptions are thrown with valid arguments 13 | assertDoesNotThrow(() -> Announcer.announce("net.openhft", "chronicle-queue")); 14 | } 15 | 16 | @Test 17 | void testAnnounceWithNullGroupId() { 18 | assertThrows(NullPointerException.class, () -> Announcer.announce(null, "chronicle-queue")); 19 | } 20 | 21 | @Test 22 | void testAnnounceWithNullArtifactId() { 23 | assertThrows(NullPointerException.class, () -> Announcer.announce("net.openhft", null)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/cleaner/impl/jdk9/Jdk9ByteBufferCleanerServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.cleaner.impl.jdk9; 20 | 21 | import net.openhft.chronicle.core.CoreTestCommon; 22 | import net.openhft.chronicle.core.Jvm; 23 | import net.openhft.chronicle.core.cleaner.impl.CleanerTestUtil; 24 | import net.openhft.chronicle.core.internal.cleaner.Jdk9ByteBufferCleanerService; 25 | import org.junit.Test; 26 | 27 | import static org.junit.Assume.assumeTrue; 28 | 29 | public class Jdk9ByteBufferCleanerServiceTest extends CoreTestCommon { 30 | @Test 31 | public void shouldCleanBuffer() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { 32 | assumeTrue(Jvm.isJava9Plus()); 33 | 34 | CleanerTestUtil.test(new Jdk9ByteBufferCleanerService()::clean); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/cleaner/impl/reflect/ReflectionBasedByteBufferCleanerServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package net.openhft.chronicle.core.cleaner.impl.reflect; 19 | 20 | import net.openhft.chronicle.core.CoreTestCommon; 21 | import net.openhft.chronicle.core.cleaner.impl.CleanerTestUtil; 22 | import net.openhft.chronicle.core.internal.cleaner.ReflectionBasedByteBufferCleanerService; 23 | import org.junit.Test; 24 | 25 | public class ReflectionBasedByteBufferCleanerServiceTest extends CoreTestCommon { 26 | @Test 27 | public void shouldCleanBuffer() { 28 | CleanerTestUtil.test(new ReflectionBasedByteBufferCleanerService()::clean); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/internal/CpuClassTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.internal; 2 | 3 | import net.openhft.chronicle.core.Jvm; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.*; 7 | import static org.junit.Assume.assumeFalse; 8 | 9 | public class CpuClassTest { 10 | @Test 11 | public void getCpuModel() { 12 | final String cpuClass = CpuClass.getCpuModel(); 13 | System.out.println("cpuClass: " + cpuClass + ", os.name: " + System.getProperty("os.name") + ", os.arch: " + System.getProperty("os.arch")); 14 | if (Jvm.isMacArm()) { 15 | assertTrue(cpuClass, cpuClass.startsWith("Apple M")); 16 | 17 | } else if (Jvm.isArm()) { 18 | assertTrue(cpuClass, cpuClass.startsWith("ARMv") 19 | || cpuClass.startsWith("aarch64")); 20 | 21 | } else { 22 | assertTrue(cpuClass, 23 | cpuClass.contains("Intel") 24 | || (cpuClass.startsWith("AMD "))); 25 | } 26 | 27 | assertNotNull(cpuClass); 28 | } 29 | 30 | @Test 31 | public void removingTag() { 32 | // TODO FIX on MacOS. sysctl -a returned 141, https://github.com/OpenHFT/Chronicle-Core/issues/557 33 | assumeFalse(net.openhft.chronicle.core.internal.Bootstrap.IS_MAC); 34 | final String actual = CpuClass.removingTag().apply("tag: value"); 35 | assertEquals("value", actual); 36 | } 37 | 38 | @Test 39 | public void getCpuModelShouldReturnNonNullValue() { 40 | assertNotNull(CpuClass.getCpuModel(), "CPU model should not be null"); 41 | } 42 | 43 | @Test 44 | public void getCpuModelShouldReturnNonEmptyValue() { 45 | assertNotEquals("", CpuClass.getCpuModel(), "CPU model should not be an empty string"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/internal/ReferenceCountedUtilsTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.internal; 2 | 3 | import net.openhft.chronicle.core.io.AbstractReferenceCounted; 4 | import org.junit.jupiter.api.AfterEach; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | import static org.mockito.Mockito.*; 10 | 11 | public class ReferenceCountedUtilsTest { 12 | 13 | @BeforeEach 14 | public void setUp() { 15 | ReferenceCountedUtils.enableReferenceTracing(); 16 | } 17 | 18 | @AfterEach 19 | public void tearDown() { 20 | ReferenceCountedUtils.disableReferenceTracing(); 21 | } 22 | 23 | @Test 24 | public void unmonitorShouldRemoveReference() { 25 | AbstractReferenceCounted referenceCounted = mock(AbstractReferenceCounted.class); 26 | when(referenceCounted.refCount()).thenReturn(1); 27 | 28 | ReferenceCountedUtils.add(referenceCounted); 29 | ReferenceCountedUtils.unmonitor(referenceCounted); 30 | 31 | assertDoesNotThrow(ReferenceCountedUtils::assertReferencesReleased, "Unmonitored references should not be checked"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/internal/cleaner/Jdk9ByteBufferCleanerServiceTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.internal.cleaner; 2 | 3 | import net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService.Impact; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.BeforeEach; 6 | 7 | import java.nio.ByteBuffer; 8 | 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class Jdk9ByteBufferCleanerServiceTest { 12 | 13 | private Jdk9ByteBufferCleanerService cleanerService; 14 | 15 | @BeforeEach 16 | public void setUp() { 17 | cleanerService = new Jdk9ByteBufferCleanerService(); 18 | } 19 | 20 | @Test 21 | public void cleanInvalidByteBuffer() { 22 | ByteBuffer buffer = ByteBuffer.allocate(1024); 23 | assertThrows(Exception.class, () -> cleanerService.clean(buffer)); 24 | } 25 | 26 | @Test 27 | public void impactShouldBeNoImpact() { 28 | assertEquals(Impact.NO_IMPACT, cleanerService.impact()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/internal/cleaner/ReflectionBasedByteBufferCleanerServiceTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.internal.cleaner; 2 | 3 | import net.openhft.chronicle.core.internal.cleaner.ReflectionBasedByteBufferCleanerService; 4 | import net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService.Impact; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.condition.EnabledIfSystemProperty; 7 | 8 | import java.nio.ByteBuffer; 9 | 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | public class ReflectionBasedByteBufferCleanerServiceTest { 13 | 14 | private final ReflectionBasedByteBufferCleanerService cleanerService = new ReflectionBasedByteBufferCleanerService(); 15 | 16 | @Test 17 | @EnabledIfSystemProperty(named = "java.version", matches = "1\\.8.*") 18 | public void cleanShouldWorkOnJava8() { 19 | ByteBuffer buffer = ByteBuffer.allocateDirect(1024); 20 | assertDoesNotThrow(() -> cleanerService.clean(buffer), "Cleaning a direct buffer should not throw an exception on Java 8"); 21 | } 22 | 23 | @Test 24 | @EnabledIfSystemProperty(named = "java.version", matches = "9|1[0-9].*") 25 | public void cleanShouldWorkOnJava9Plus() { 26 | ByteBuffer buffer = ByteBuffer.allocateDirect(1024); 27 | assertDoesNotThrow(() -> cleanerService.clean(buffer), "Cleaning a direct buffer should not throw an exception on Java 9+"); 28 | } 29 | 30 | @Test 31 | public void impactShouldReturnValidImpact() { 32 | Impact impact = cleanerService.impact(); 33 | assertTrue(impact == Impact.SOME_IMPACT || impact == Impact.UNAVAILABLE, "Impact should be either SOME_IMPACT or UNAVAILABLE"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/internal/util/DirectBufferUtilTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.internal.util; 2 | 3 | import net.openhft.chronicle.core.Jvm; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.nio.ByteBuffer; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | import static org.junit.jupiter.api.Assumptions.assumeFalse; 10 | 11 | public class DirectBufferUtilTest { 12 | 13 | @Test 14 | public void directBufferClassShouldReturnCorrectClass() { 15 | assertEquals(sun.nio.ch.DirectBuffer.class, DirectBufferUtil.directBufferClass(), "DirectBuffer class should be returned"); 16 | } 17 | 18 | @Test 19 | public void cleanIfInstanceOfDirectBufferShouldCleanDirectBuffer() { 20 | assumeFalse(Jvm.isJava9Plus()); 21 | ByteBuffer directBuffer = ByteBuffer.allocateDirect(1024); 22 | 23 | assertDoesNotThrow(() -> DirectBufferUtil.cleanIfInstanceOfDirectBuffer(directBuffer), "Cleaning a direct buffer should not throw an exception"); 24 | } 25 | 26 | @Test 27 | public void cleanIfInstanceOfDirectBufferShouldNotThrowForNonDirectBuffer() { 28 | ByteBuffer nonDirectBuffer = ByteBuffer.allocate(1024); 29 | 30 | assertDoesNotThrow(() -> DirectBufferUtil.cleanIfInstanceOfDirectBuffer(nonDirectBuffer), "Non-direct buffer should not throw an exception"); 31 | } 32 | 33 | @Test 34 | public void addressOrThrowShouldReturnAddressForDirectBuffer() { 35 | ByteBuffer directBuffer = ByteBuffer.allocateDirect(1024); 36 | 37 | assertDoesNotThrow(() -> DirectBufferUtil.addressOrThrow(directBuffer), "Getting address of a direct buffer should not throw an exception"); 38 | } 39 | 40 | @Test 41 | public void addressOrThrowShouldThrowForNonDirectBuffer() { 42 | ByteBuffer nonDirectBuffer = ByteBuffer.allocate(1024); 43 | 44 | assertThrows(ClassCastException.class, () -> DirectBufferUtil.addressOrThrow(nonDirectBuffer), "Non-direct buffer should throw ClassCastException"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/internal/util/NopThreadConfinementAsserterTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.internal.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | public class NopThreadConfinementAsserterTest { 8 | 9 | @Test 10 | public void assertThreadConfinedShouldDoNothing() { 11 | NopThreadConfinementAsserter asserter = NopThreadConfinementAsserter.INSTANCE; 12 | 13 | assertDoesNotThrow(asserter::assertThreadConfined, "assertThreadConfined should not throw any exceptions"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/CleaningRandomAccessFileTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | public class CleaningRandomAccessFileTest { 9 | 10 | @Test 11 | public void testOpenAndClose() throws IOException { 12 | File tempFile = File.createTempFile("test", "raf"); 13 | CleaningRandomAccessFile raf = new CleaningRandomAccessFile(tempFile, "rw"); 14 | 15 | // Write and read to verify file is open 16 | raf.writeUTF("test"); 17 | raf.seek(0); 18 | assertEquals("test", raf.readUTF()); 19 | 20 | raf.close(); 21 | 22 | assertThrows(IOException.class, () -> raf.writeUTF("should fail")); 23 | 24 | assertTrue(tempFile.delete()); 25 | } 26 | 27 | @Test 28 | public void testFinalizeAndCleanup() throws IOException { 29 | File tempFile = File.createTempFile("test", "raf"); 30 | 31 | new CleaningRandomAccessFile(tempFile, "rw"); 32 | 33 | System.gc(); 34 | System.runFinalization(); 35 | 36 | assertTrue(tempFile.delete()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/ClosedIORuntimeExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import static org.junit.Assert.*; 4 | import org.junit.Test; 5 | 6 | public class ClosedIORuntimeExceptionTest { 7 | 8 | @Test 9 | public void testConstructorWithMessage() { 10 | String testMessage = "Test message"; 11 | ClosedIORuntimeException exception = new ClosedIORuntimeException(testMessage); 12 | 13 | assertEquals("The message should match the one provided to the constructor", 14 | testMessage, exception.getMessage()); 15 | } 16 | 17 | @Test 18 | public void testConstructorWithMessageAndCause() { 19 | String testMessage = "Test message"; 20 | Throwable testCause = new Throwable("Test cause"); 21 | ClosedIORuntimeException exception = new ClosedIORuntimeException(testMessage, testCause); 22 | 23 | assertEquals("The message should match the one provided to the constructor", 24 | testMessage, exception.getMessage()); 25 | assertEquals("The cause should match the one provided to the constructor", 26 | testCause, exception.getCause()); 27 | } 28 | 29 | @Test 30 | public void testConstructorWithNullCause() { 31 | String testMessage = "Test message"; 32 | ClosedIORuntimeException exception = new ClosedIORuntimeException(testMessage, null); 33 | 34 | assertEquals("The message should match the one provided to the constructor", 35 | testMessage, exception.getMessage()); 36 | assertNull("The cause should be null", exception.getCause()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/IOBenchmarkMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.io; 20 | 21 | import java.io.File; 22 | import java.io.FileWriter; 23 | import java.io.IOException; 24 | 25 | public enum IOBenchmarkMain { 26 | ; // none 27 | 28 | public static void main(String[] args) throws IOException { 29 | String path = args.length > 0 ? args[0] : "."; 30 | File dir = new File(path, "deleteme"); 31 | if (!dir.exists()) 32 | dir.mkdir(); 33 | int count = 0; 34 | long start = System.nanoTime(); 35 | do { 36 | try (FileWriter fw = new FileWriter(new File(dir, "file" + count))) { 37 | fw.write("Hello World"); 38 | count++; 39 | } 40 | } while (start + 3e9 > System.nanoTime()); 41 | for (int i = 0; i < count; i++) { 42 | new File(dir, "file" + i).delete(); 43 | } 44 | long time = System.nanoTime() - start; 45 | System.out.printf("IO Throughput %,d IO/s%n", 46 | (long) (count * 2 * 1e9 / time)); 47 | dir.delete(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/ManagedCloseableTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import net.openhft.chronicle.core.Jvm; 4 | import net.openhft.chronicle.core.io.ManagedCloseable; 5 | import org.junit.Before; 6 | import org.junit.jupiter.api.Assumptions; 7 | import org.junit.jupiter.api.BeforeEach; 8 | import org.junit.jupiter.api.Test; 9 | import org.mockito.Mockito; 10 | 11 | import static org.junit.Assume.assumeTrue; 12 | import static org.mockito.Mockito.*; 13 | import static org.junit.jupiter.api.Assertions.*; 14 | 15 | public class ManagedCloseableTest { 16 | @BeforeEach 17 | public void mockitoNotSupportedOnJava21() { 18 | Assumptions.assumeTrue(Jvm.majorVersion() <= 17); 19 | } 20 | @Test 21 | public void testWarnAndCloseIfNotClosed() { 22 | ManagedCloseable closeable = spy(ManagedCloseable.class); 23 | 24 | when(closeable.isClosing()).thenReturn(false); 25 | 26 | closeable.warnAndCloseIfNotClosed(); 27 | 28 | verify(closeable, times(1)).close(); 29 | } 30 | 31 | @Test 32 | public void testThrowExceptionIfClosed() { 33 | ManagedCloseable closeable = Mockito.spy(ManagedCloseable.class); 34 | 35 | when(closeable.isClosing()).thenReturn(true); 36 | when(closeable.isClosed()).thenReturn(true); 37 | 38 | assertThrows(ClosedIllegalStateException.class, closeable::throwExceptionIfClosed); 39 | } 40 | 41 | @Test 42 | public void testCreatedHere() { 43 | ManagedCloseable closeable = Mockito.spy(ManagedCloseable.class); 44 | 45 | assertNull(closeable.createdHere()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/MonitorReferenceCountedContractTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | /** 8 | * Any implementation of {@link ReferenceCountedTracer} should implement a test class 9 | * that extends this class 10 | */ 11 | public abstract class MonitorReferenceCountedContractTest extends ReferenceCountedTracerContractTest { 12 | 13 | @Override 14 | protected abstract MonitorReferenceCounted createReferenceCounted(); 15 | 16 | @Test 17 | public void warnAndReleaseWillLogAWarningAndReleaseWhenMonitored() { 18 | final MonitorReferenceCounted referenceCounted = createReferenceCounted(); 19 | referenceCounted.unmonitored(false); 20 | referenceCounted.warnAndReleaseIfNotReleased(); 21 | assertEquals(0, referenceCounted.refCount()); 22 | expectException("Discarded without being released"); 23 | } 24 | 25 | @Test 26 | public void warnAndReleaseWillJustReleaseWhenMonitored() { 27 | final MonitorReferenceCounted referenceCounted = createReferenceCounted(); 28 | referenceCounted.unmonitored(true); 29 | referenceCounted.warnAndReleaseIfNotReleased(); 30 | assertEquals(0, referenceCounted.refCount()); 31 | } 32 | 33 | @Test 34 | public void warnAndReleaseWillDoNothingIfTheResourceIsAlreadyReleased() { 35 | final MonitorReferenceCounted referenceCounted = createReferenceCounted(); 36 | referenceCounted.unmonitored(false); 37 | referenceCounted.releaseLast(); 38 | referenceCounted.warnAndReleaseIfNotReleased(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/ReferenceChangeListenerTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.mockito.Mockito.*; 5 | 6 | public class ReferenceChangeListenerTest { 7 | 8 | @Test 9 | public void testOnReferenceAdded() { 10 | ReferenceChangeListener listener = mock(ReferenceChangeListener.class); 11 | ReferenceCounted referenceCounted = mock(ReferenceCounted.class); 12 | ReferenceOwner referenceOwner = mock(ReferenceOwner.class); 13 | 14 | listener.onReferenceAdded(referenceCounted, referenceOwner); 15 | 16 | verify(listener, times(1)).onReferenceAdded(referenceCounted, referenceOwner); 17 | } 18 | 19 | @Test 20 | public void testOnReferenceRemoved() { 21 | ReferenceChangeListener listener = mock(ReferenceChangeListener.class); 22 | ReferenceCounted referenceCounted = mock(ReferenceCounted.class); 23 | ReferenceOwner referenceOwner = mock(ReferenceOwner.class); 24 | 25 | listener.onReferenceRemoved(referenceCounted, referenceOwner); 26 | 27 | verify(listener, times(1)).onReferenceRemoved(referenceCounted, referenceOwner); 28 | } 29 | 30 | @Test 31 | public void testOnReferenceTransferred() { 32 | ReferenceChangeListener listener = mock(ReferenceChangeListener.class); 33 | ReferenceCounted referenceCounted = mock(ReferenceCounted.class); 34 | ReferenceOwner fromOwner = mock(ReferenceOwner.class); 35 | ReferenceOwner toOwner = mock(ReferenceOwner.class); 36 | 37 | listener.onReferenceTransferred(referenceCounted, fromOwner, toOwner); 38 | 39 | verify(listener, times(1)).onReferenceTransferred(referenceCounted, fromOwner, toOwner); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/ReferenceOwnerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.io; 20 | 21 | import junit.framework.TestCase; 22 | import org.junit.Test; 23 | 24 | import java.util.HashSet; 25 | import java.util.Set; 26 | 27 | public class ReferenceOwnerTest extends TestCase { 28 | @Test 29 | public void testReferenceId() { 30 | Set ints = new HashSet<>(); 31 | for (int i = 0; i < 101; i++) 32 | ints.add(new VanillaReferenceOwner("hi").referenceId()); 33 | assertEquals(100, ints.size(), 1); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/SimpleCloseableTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import net.openhft.chronicle.core.io.SimpleCloseable; 4 | import org.junit.jupiter.api.Test; 5 | import static org.junit.jupiter.api.Assertions.*; 6 | import static org.mockito.Mockito.*; 7 | 8 | public class SimpleCloseableTest { 9 | 10 | public static class TestableSimpleCloseable extends SimpleCloseable { 11 | private boolean performCloseCalled = false; 12 | 13 | @Override 14 | protected void performClose() { 15 | if (!performCloseCalled) { 16 | super.performClose(); 17 | performCloseCalled = true; 18 | } 19 | } 20 | 21 | boolean isPerformCloseCalled() { 22 | return performCloseCalled; 23 | } 24 | } 25 | 26 | @Test 27 | public void testClose() { 28 | TestableSimpleCloseable closeable = new TestableSimpleCloseable(); 29 | 30 | assertFalse(closeable.isClosed()); 31 | closeable.close(); 32 | assertTrue(closeable.isClosed()); 33 | assertTrue(closeable.isPerformCloseCalled()); 34 | 35 | closeable.close(); 36 | assertTrue(closeable.isClosed()); 37 | } 38 | 39 | @Test 40 | public void testIsClosed() { 41 | TestableSimpleCloseable closeable = new TestableSimpleCloseable(); 42 | 43 | assertFalse(closeable.isClosed()); 44 | closeable.close(); 45 | assertTrue(closeable.isClosed()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/SyncableTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.mockito.Mockito.*; 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | public class SyncableTest { 8 | 9 | public static class SyncableImpl implements Syncable { 10 | boolean synced = false; 11 | 12 | @Override 13 | public void sync() { 14 | synced = true; 15 | } 16 | } 17 | 18 | @Test 19 | public void syncIfAvailableShouldCallSyncOnSyncableObjects() { 20 | Syncable syncableMock = mock(Syncable.class); 21 | Syncable.syncIfAvailable(syncableMock); 22 | 23 | verify(syncableMock, times(1)).sync(); 24 | } 25 | 26 | @Test 27 | public void syncIfAvailableShouldNotThrowExceptionForNonSyncableObjects() { 28 | Object nonSyncableObject = new Object(); 29 | 30 | assertDoesNotThrow(() -> Syncable.syncIfAvailable(nonSyncableObject)); 31 | } 32 | 33 | @Test 34 | public void syncShouldSetSyncedToTrueForSyncableImpl() { 35 | SyncableImpl syncableImpl = new SyncableImpl(); 36 | assertFalse(syncableImpl.synced); 37 | 38 | syncableImpl.sync(); 39 | 40 | assertTrue(syncableImpl.synced); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/ThreadingIllegalStateExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.junit.jupiter.api.Assertions.*; 5 | 6 | public class ThreadingIllegalStateExceptionTest { 7 | 8 | @Test 9 | public void testConstructorWithMessageAndCause() { 10 | String expectedMessage = "Custom threading error message"; 11 | Throwable expectedCause = new RuntimeException("Cause of error"); 12 | 13 | ThreadingIllegalStateException exception = new ThreadingIllegalStateException(expectedMessage, expectedCause); 14 | 15 | assertEquals(expectedMessage, exception.getMessage()); 16 | assertEquals(expectedCause, exception.getCause()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/ValidatableUtilTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.junit.jupiter.api.Assertions.*; 5 | import static org.mockito.Mockito.*; 6 | 7 | public class ValidatableUtilTest { 8 | 9 | @Test 10 | public void testValidateToggle() { 11 | assertTrue(ValidatableUtil.validateEnabled()); 12 | 13 | ValidatableUtil.startValidateDisabled(); 14 | assertFalse(ValidatableUtil.validateEnabled()); 15 | 16 | ValidatableUtil.endValidateDisabled(); 17 | assertTrue(ValidatableUtil.validateEnabled()); 18 | } 19 | 20 | @Test 21 | public void testEndValidateDisabledWithoutStart() { 22 | AssertionError exception = assertThrows(AssertionError.class, ValidatableUtil::endValidateDisabled); 23 | assertNotNull(exception); 24 | } 25 | 26 | @Test 27 | public void testValidate() throws InvalidMarshallableException { 28 | Validatable validatable = mock(Validatable.class); 29 | ValidatableUtil.validate(validatable); 30 | 31 | verify(validatable, times(1)).validate(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/VanillaReferenceCountedTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import java.util.concurrent.atomic.AtomicInteger; 7 | 8 | import static org.junit.Assert.assertNull; 9 | 10 | public class VanillaReferenceCountedTest extends MonitorReferenceCountedContractTest { 11 | 12 | private AtomicInteger onReleasedCallCount; 13 | 14 | @Before 15 | public void setUp() { 16 | onReleasedCallCount = new AtomicInteger(0); 17 | } 18 | 19 | @Override 20 | protected VanillaReferenceCounted createReferenceCounted() { 21 | return new VanillaReferenceCounted(onReleasedCallCount::incrementAndGet, VanillaReferenceCounted.class); 22 | } 23 | 24 | @Test 25 | public void createdHereWillReturnNull() { 26 | final VanillaReferenceCounted referenceCounted = createReferenceCounted(); 27 | assertNull(referenceCounted.createdHere()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/io/WgetTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.io; 2 | 3 | import org.junit.jupiter.api.Disabled; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.IOException; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertFalse; 9 | import static org.junit.jupiter.api.Assertions.assertThrows; 10 | 11 | public class WgetTest { 12 | 13 | @Disabled("Temporarily disabled") 14 | @Test 15 | public void testHttpGetRequest() throws IOException { 16 | String testUrl = "http://example.com"; 17 | StringBuilder sb = new StringBuilder(); 18 | 19 | Wget.url(testUrl, sb); 20 | 21 | assertFalse(sb.toString().isEmpty()); 22 | } 23 | 24 | @Test 25 | public void testHttpGetRequestWithInvalidUrl() { 26 | String invalidUrl = "http://invalid.url"; 27 | StringBuilder sb = new StringBuilder(); 28 | 29 | assertThrows(IOException.class, () -> Wget.url(invalidUrl, sb)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/jitter/LongPingPongMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.jitter; 20 | 21 | import net.openhft.chronicle.core.util.Histogram; 22 | 23 | public class LongPingPongMain { 24 | static volatile long pingTime = 0; 25 | static volatile long pingCount = 0; 26 | static volatile long pongCount = 0; 27 | static volatile boolean running = true; 28 | 29 | public static void main(String[] args) { 30 | Histogram h = new Histogram(32, 7); 31 | Thread pong = new Thread(() -> { 32 | while (running) { 33 | 34 | } 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/onoes/ExceptionKeyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.onoes; 20 | 21 | import net.openhft.chronicle.core.CoreTestCommon; 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotEquals; 26 | 27 | public class ExceptionKeyTest extends CoreTestCommon { 28 | 29 | @Test 30 | public void testEqualsAndHashCode() { 31 | ExceptionKey ek1 = new ExceptionKey(LogLevel.PERF, getClass(), "one", null); 32 | ExceptionKey ek1b = new ExceptionKey(LogLevel.PERF, getClass(), "one", null); 33 | assertEquals(ek1, ek1b); 34 | assertEquals(ek1.hashCode(), ek1b.hashCode()); 35 | assertEquals("ExceptionKey{level=PERF, clazz=class net.openhft.chronicle.core.onoes.ExceptionKeyTest, message='one', throwable=}", ek1.toString()); 36 | ExceptionKey ek2 = new ExceptionKey(LogLevel.WARN, getClass(), "two", null); 37 | assertEquals("ExceptionKey{level=WARN, clazz=class net.openhft.chronicle.core.onoes.ExceptionKeyTest, message='two', throwable=}", ek2.toString()); 38 | assertNotEquals(ek1, ek2); 39 | assertNotEquals(ek1.hashCode(), ek2.hashCode()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/onoes/NullExceptionHandlerTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.onoes; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.slf4j.Logger; 5 | import static org.mockito.Mockito.*; 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class NullExceptionHandlerTest { 9 | 10 | @Test 11 | void onMethodShouldDoNothing() { 12 | Logger mockLogger = mock(Logger.class); 13 | Throwable mockThrowable = new RuntimeException("Test exception"); 14 | 15 | assertDoesNotThrow(() -> NullExceptionHandler.NOTHING.on(mockLogger, "Test message", mockThrowable)); 16 | 17 | // Since the method should do nothing, there should be no interactions with the logger 18 | verifyNoInteractions(mockLogger); 19 | } 20 | 21 | @Test 22 | void isEnabledShouldAlwaysReturnFalse() { 23 | assertFalse(NullExceptionHandler.NOTHING.isEnabled(String.class)); 24 | assertFalse(NullExceptionHandler.NOTHING.isEnabled(Integer.class)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/onoes/ThreadLocalisedExceptionHandlerTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.onoes; 2 | 3 | import org.junit.jupiter.api.*; 4 | import static org.junit.jupiter.api.Assertions.*; 5 | import static org.mockito.Mockito.*; 6 | 7 | public class ThreadLocalisedExceptionHandlerTest { 8 | 9 | private ExceptionHandler defaultHandler; 10 | private ThreadLocalisedExceptionHandler tlExceptionHandler; 11 | 12 | @BeforeEach 13 | public void setUp() { 14 | defaultHandler = mock(ExceptionHandler.class); 15 | tlExceptionHandler = new ThreadLocalisedExceptionHandler(defaultHandler); 16 | } 17 | 18 | @Test 19 | public void testUnwrapExceptionHandler() { 20 | assertSame(defaultHandler, ThreadLocalisedExceptionHandler.unwrap(tlExceptionHandler)); 21 | } 22 | 23 | @Test 24 | public void testIsEnabled() { 25 | when(defaultHandler.isEnabled(Exception.class)).thenReturn(true); 26 | assertTrue(tlExceptionHandler.isEnabled(Exception.class)); 27 | } 28 | 29 | // Add more tests as necessary for other methods and edge cases. 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.pom; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import java.util.Properties; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | import static org.junit.jupiter.api.Assertions.assertThrows; 8 | 9 | class PomPropertiesTest { 10 | 11 | @Test 12 | void testCreateWithValidArguments() { 13 | assertEquals("{}", 14 | PomProperties.create("net.openhft", "chronicle-queue").toString()); 15 | } 16 | 17 | @Test 18 | void testCreateWithNullGroupId() { 19 | assertThrows(NullPointerException.class, 20 | () -> PomProperties.create(null, "chronicle-queue").toString()); 21 | } 22 | 23 | @Test 24 | void testCreateWithNullArtifactId() { 25 | assertThrows(NullPointerException.class, 26 | () -> PomProperties.create("net.openhft", null).toString()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/pool/ClassLookupTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.pool; 2 | 3 | import net.openhft.chronicle.core.util.ClassNotFoundRuntimeException; 4 | import org.junit.jupiter.api.*; 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class ClassLookupTest { 8 | 9 | private ClassLookup classLookup = ClassAliasPool.CLASS_ALIASES; 10 | 11 | @Test 12 | void testClassLookupByName() { 13 | Class clazz = classLookup.forName("java.lang.String"); 14 | assertEquals(String.class, clazz); 15 | } 16 | 17 | @Test 18 | void testAddingAliasAndLookupByAlias() { 19 | classLookup.addAlias(String.class, "StringAlias"); 20 | Class clazz = classLookup.forName("StringAlias"); 21 | assertEquals(String.class, clazz); 22 | } 23 | 24 | @Test 25 | void testImmutabilityOfWrappedInstance() { 26 | ClassLookup wrapped = classLookup.wrap(); 27 | wrapped.addAlias(String.class, "StringAlias"); 28 | 29 | assertThrows(ClassNotFoundRuntimeException.class, () -> classLookup.forName("StringAlias")); 30 | } 31 | 32 | @Test 33 | void testLookupOfLambdaClass() { 34 | Runnable lambda = () -> {}; 35 | assertThrows(IllegalArgumentException.class, () -> classLookup.nameFor(lambda.getClass())); 36 | } 37 | 38 | // Additional tests as necessary... 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/pool/Ecn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.pool; 20 | 21 | public enum Ecn { 22 | 23 | EBS_LIVE_NYK, 24 | RFX, 25 | PARFX, 26 | EBS_LDN, 27 | HST, 28 | GFX, 29 | EBS_LIVE_LDN, 30 | LMAX, 31 | CNX, 32 | EBS_NYK, 33 | FXCM, 34 | MAKO, 35 | EBS_HEDGE, 36 | FXALL_MID, 37 | ESPEED, 38 | XTX, 39 | XTX2, 40 | RFXSBE, 41 | NONE, 42 | INTERNAL_SOR, 43 | INTERNAL_ALGO 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/pool/EcnDynamic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.pool; 20 | 21 | import net.openhft.chronicle.core.util.CoreDynamicEnum; 22 | 23 | public enum EcnDynamic implements CoreDynamicEnum { 24 | 25 | EBS_LIVE_NYK, 26 | RFX, 27 | PARFX, 28 | EBS_LDN, 29 | HST, 30 | GFX, 31 | EBS_LIVE_LDN, 32 | LMAX, 33 | CNX, 34 | EBS_NYK, 35 | FXCM, 36 | MAKO, 37 | EBS_HEDGE, 38 | FXALL_MID, 39 | ESPEED, 40 | XTX, 41 | XTX2, 42 | RFXSBE, 43 | NONE, 44 | INTERNAL_SOR, 45 | INTERNAL_ALGO 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/pool/EnumCacheTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.pool; 2 | 3 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/pool/ParsingCacheTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.pool; 20 | 21 | import net.openhft.chronicle.core.CoreTestCommon; 22 | import org.jetbrains.annotations.NotNull; 23 | import org.jetbrains.annotations.Nullable; 24 | import org.junit.Test; 25 | 26 | import java.math.BigDecimal; 27 | 28 | import static org.junit.Assert.*; 29 | 30 | public class ParsingCacheTest extends CoreTestCommon { 31 | @Test 32 | public void intern() throws Exception { 33 | @NotNull ParsingCache pc = new ParsingCache<>(128, BigDecimal::new); 34 | @Nullable BigDecimal bd1 = pc.intern("1.234"); 35 | @Nullable BigDecimal bd2 = pc.intern("12.234"); 36 | @Nullable BigDecimal bd1b = pc.intern("1.234"); 37 | assertNotEquals(bd1, bd2); 38 | assertSame(bd1, bd1b); 39 | assertEquals(2, pc.valueCount()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/pool/StaticEnumClassTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.pool; 20 | 21 | import net.openhft.chronicle.core.CoreTestCommon; 22 | import net.openhft.chronicle.core.Maths; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | public class StaticEnumClassTest extends CoreTestCommon { 27 | 28 | @Test 29 | public void testInitialSize() throws IllegalArgumentException { 30 | EnumCache ecnEnumCache = EnumCache.of(Ecn.class); 31 | assertEquals(32, Maths.nextPower2(ecnEnumCache.size(), 1)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/pool/YesNo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.pool; 20 | 21 | import net.openhft.chronicle.core.util.CoreDynamicEnum; 22 | 23 | public enum YesNo implements CoreDynamicEnum { 24 | Yes, No 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/scoped/WeakReferenceScopedResourceTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.scoped; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.concurrent.atomic.AtomicLong; 7 | 8 | import static org.junit.Assert.assertNotNull; 9 | import static org.junit.Assert.assertNull; 10 | 11 | class WeakReferenceScopedResourceTest { 12 | 13 | private ScopedThreadLocal scopedThreadLocal; 14 | 15 | @BeforeEach 16 | void setUp() { 17 | scopedThreadLocal = new ScopedThreadLocal<>(AtomicLong::new, 3); 18 | } 19 | 20 | @Test 21 | void resourceIsCreatedPreAcquire() { 22 | final WeakReferenceScopedResource sr = new WeakReferenceScopedResource<>(scopedThreadLocal, AtomicLong::new); 23 | assertNull(sr.get()); // There should be nothing in it (this would never happen in the real world) 24 | sr.preAcquire(); 25 | assertNotNull(sr.get()); 26 | } 27 | 28 | @Test 29 | void strongReferenceIsCreatedPreAcquire() { 30 | final WeakReferenceScopedResource sr = new WeakReferenceScopedResource<>(scopedThreadLocal, AtomicLong::new); 31 | sr.preAcquire(); // creates the strong reference 32 | assertNotNull(sr.get()); 33 | System.gc(); 34 | assertNotNull(sr.get()); 35 | sr.close(); // clears the strong reference 36 | System.gc(); 37 | assertNull(sr.get()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/shutdown/PriorityHookTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.shutdown; 2 | 3 | import org.junit.jupiter.api.*; 4 | import org.mockito.InOrder; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | import static org.mockito.Mockito.*; 8 | 9 | public class PriorityHookTest { 10 | 11 | @Test 12 | public void testAddHook() { 13 | Runnable hook1 = mock(Runnable.class); 14 | boolean added1 = PriorityHook.add(1, hook1); 15 | assertFalse(added1); 16 | 17 | boolean addedAgain = PriorityHook.add(1, hook1); 18 | assertFalse(addedAgain); 19 | } 20 | 21 | @Test 22 | public void testHookExecutionOrder() { 23 | Runnable hook1 = mock(Runnable.class); 24 | Runnable hook2 = mock(Runnable.class); 25 | PriorityHook.add(1, hook1); 26 | PriorityHook.add(2, hook2); 27 | 28 | PriorityHook.getRegisteredHook().onShutdown(); 29 | 30 | InOrder inOrder = inOrder(hook1, hook2); 31 | ((InOrder) inOrder).verify(hook1).run(); 32 | inOrder.verify(hook2).run(); 33 | } 34 | 35 | @Test 36 | public void testClearHooks() { 37 | Runnable hook = mock(Runnable.class); 38 | PriorityHook.add(1, hook); 39 | 40 | PriorityHook.clear(); 41 | 42 | assertNull(PriorityHook.getRegisteredHook()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/threads/HandlerPriorityTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.threads; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.junit.jupiter.api.Assertions.*; 5 | 6 | public class HandlerPriorityTest { 7 | 8 | @Test 9 | public void testAliasForPrioritiesWithAliases() { 10 | assertEquals(HandlerPriority.MEDIUM, HandlerPriority.REPLICATION.alias()); 11 | assertEquals(HandlerPriority.TIMER, HandlerPriority.REPLICATION_TIMER.alias()); 12 | assertEquals(HandlerPriority.MEDIUM, HandlerPriority.CONCURRENT.alias()); 13 | } 14 | 15 | @Test 16 | public void testAliasForPrioritiesWithoutAliases() { 17 | assertEquals(HandlerPriority.HIGH, HandlerPriority.HIGH.alias()); 18 | assertEquals(HandlerPriority.MEDIUM, HandlerPriority.MEDIUM.alias()); 19 | assertEquals(HandlerPriority.TIMER, HandlerPriority.TIMER.alias()); 20 | assertEquals(HandlerPriority.DAEMON, HandlerPriority.DAEMON.alias()); 21 | assertEquals(HandlerPriority.MONITOR, HandlerPriority.MONITOR.alias()); 22 | assertEquals(HandlerPriority.BLOCKING, HandlerPriority.BLOCKING.alias()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/threads/InterruptedRuntimeExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.threads; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.junit.jupiter.api.Assertions.*; 5 | 6 | class InterruptedRuntimeExceptionTest { 7 | 8 | @Test 9 | void defaultConstructorShouldCreateExceptionWithNoMessageOrCause() { 10 | InterruptedRuntimeException exception = new InterruptedRuntimeException(); 11 | assertNull(exception.getMessage()); 12 | assertNull(exception.getCause()); 13 | } 14 | 15 | @Test 16 | void constructorWithMessageShouldSetCorrectMessage() { 17 | String message = "Interrupted"; 18 | InterruptedRuntimeException exception = new InterruptedRuntimeException(message); 19 | assertEquals(message, exception.getMessage()); 20 | assertNull(exception.getCause()); 21 | } 22 | 23 | @Test 24 | void constructorWithMessageAndCauseShouldSetBothCorrectly() { 25 | String message = "Interrupted"; 26 | Throwable cause = new RuntimeException("Cause"); 27 | InterruptedRuntimeException exception = new InterruptedRuntimeException(message, cause); 28 | assertEquals(message, exception.getMessage()); 29 | assertEquals(cause, exception.getCause()); 30 | } 31 | 32 | @Test 33 | void constructorWithCauseShouldSetCauseAndDeriveMessage() { 34 | Throwable cause = new RuntimeException("Cause"); 35 | InterruptedRuntimeException exception = new InterruptedRuntimeException(cause); 36 | assertEquals(cause.toString(), exception.getMessage()); 37 | assertEquals(cause, exception.getCause()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/threads/ReferenceQueue.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.threads; 2 | 3 | public class ReferenceQueue { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/threads/ThreadDumpTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.threads; 2 | 3 | import net.openhft.chronicle.core.Jvm; 4 | import org.junit.jupiter.api.*; 5 | 6 | import static org.junit.Assume.assumeFalse; 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | public class ThreadDumpTest { 10 | 11 | private ThreadDump threadDump; 12 | 13 | @BeforeEach 14 | void setUp() { 15 | threadDump = new ThreadDump(); 16 | } 17 | 18 | @Test 19 | public void testIgnoreThread() { 20 | String ignoredThreadName = "IgnoredThread"; 21 | threadDump.ignore(ignoredThreadName); 22 | 23 | // Simulate an ignored thread 24 | Thread ignoredThread = new Thread(() -> {}, ignoredThreadName); 25 | ignoredThread.start(); 26 | 27 | threadDump.assertNoNewThreads(); 28 | 29 | // Clean up 30 | ignoredThread.interrupt(); 31 | } 32 | 33 | @Test 34 | void testAssertNoNewThreads() { 35 | threadDump.assertNoNewThreads(); 36 | } 37 | 38 | @Test 39 | void testAssertNewThreads() { 40 | assumeFalse(Jvm.isArm()); 41 | Thread newThread = new Thread(() -> { 42 | Jvm.pause(10000); 43 | }); 44 | newThread.start(); 45 | 46 | // ensure the thread has started 47 | Jvm.pause(100); 48 | 49 | // Expect an AssertionError since a new thread is running 50 | assertThrows(AssertionError.class, threadDump::assertNoNewThreads, "newThread.isAlive()= " + newThread.isAlive()); 51 | 52 | // Clean up 53 | newThread.interrupt(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/threads/ThreadLocalHelperTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.threads; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import java.lang.ref.WeakReference; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | import java.util.function.Consumer; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | class ThreadLocalHelperTest { 11 | 12 | @Test 13 | void testGetTLWithSupplier() { 14 | ThreadLocal> threadLocal = new ThreadLocal<>(); 15 | AtomicInteger counter = new AtomicInteger(0); 16 | String value = ThreadLocalHelper.getTL(threadLocal, () -> "Value" + counter.incrementAndGet()); 17 | 18 | assertEquals("Value1", value); 19 | // Ensure the same value is retrieved and not recreated 20 | assertEquals("Value1", ThreadLocalHelper.getTL(threadLocal, () -> "Value" + counter.incrementAndGet())); 21 | } 22 | 23 | @Test 24 | void testGetSTL() { 25 | ThreadLocal threadLocal = new ThreadLocal<>(); 26 | AtomicInteger counter = new AtomicInteger(0); 27 | String value = ThreadLocalHelper.getSTL(threadLocal, () -> "Value" + counter.incrementAndGet()); 28 | 29 | assertEquals("Value1", value); 30 | // Ensure the same value is retrieved and not recreated 31 | assertEquals("Value1", ThreadLocalHelper.getSTL(threadLocal, () -> "Value" + counter.incrementAndGet())); 32 | } 33 | 34 | @Test 35 | void testGetTLWithFunction() { 36 | ThreadLocal> threadLocal = new ThreadLocal<>(); 37 | String input = "123"; 38 | Integer value = ThreadLocalHelper.getTL(threadLocal, input, Integer::valueOf); 39 | 40 | assertEquals(123, value); 41 | // Ensure the same value is retrieved and not recreated 42 | assertEquals(123, ThreadLocalHelper.getTL(threadLocal, "456", Integer::valueOf)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/ByteConsumerTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class ByteConsumerTest { 8 | 9 | @Test 10 | void acceptShouldPerformOperation() { 11 | byte[] resultContainer = new byte[1]; 12 | ByteConsumer consumer = value -> resultContainer[0] = value; 13 | 14 | consumer.accept((byte) 10); 15 | 16 | assertEquals((byte) 10, resultContainer[0]); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/CharSequenceComparatorTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.junit.jupiter.api.Assertions.*; 5 | 6 | class CharSequenceComparatorTest { 7 | 8 | @Test 9 | void compareIdenticalSequences() { 10 | CharSequence seq1 = "test"; 11 | CharSequence seq2 = "test"; 12 | 13 | assertEquals(0, CharSequenceComparator.INSTANCE.compare(seq1, seq2)); 14 | } 15 | 16 | @Test 17 | void compareDifferentSequencesSameLength() { 18 | CharSequence seq1 = "abc"; 19 | CharSequence seq2 = "abd"; 20 | 21 | assertTrue(CharSequenceComparator.INSTANCE.compare(seq1, seq2) < 0); 22 | assertTrue(CharSequenceComparator.INSTANCE.compare(seq2, seq1) > 0); 23 | } 24 | 25 | @Test 26 | void compareDifferentLengthSequences() { 27 | CharSequence seq1 = "abc"; 28 | CharSequence seq2 = "abcd"; 29 | 30 | assertTrue(CharSequenceComparator.INSTANCE.compare(seq1, seq2) < 0); 31 | assertTrue(CharSequenceComparator.INSTANCE.compare(seq2, seq1) > 0); 32 | } 33 | 34 | @Test 35 | void compareEmptyAndNonEmptySequences() { 36 | CharSequence emptySeq = ""; 37 | CharSequence nonEmptySeq = "test"; 38 | 39 | assertTrue(CharSequenceComparator.INSTANCE.compare(emptySeq, nonEmptySeq) < 0); 40 | assertTrue(CharSequenceComparator.INSTANCE.compare(nonEmptySeq, emptySeq) > 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/ClassMetricsTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.junit.jupiter.api.Assertions.*; 5 | 6 | public class ClassMetricsTest { 7 | 8 | @Test 9 | public void constructorAndMethodsWorkCorrectly() { 10 | int expectedOffset = 10; 11 | int expectedLength = 20; 12 | ClassMetrics metrics = new ClassMetrics(expectedOffset, expectedLength); 13 | 14 | assertEquals(expectedOffset, metrics.offset()); 15 | assertEquals(expectedLength, metrics.length()); 16 | } 17 | 18 | @Test 19 | public void equalsAndHashCode() { 20 | ClassMetrics metrics1 = new ClassMetrics(10, 20); 21 | ClassMetrics metrics2 = new ClassMetrics(10, 20); 22 | ClassMetrics metrics3 = new ClassMetrics(15, 25); 23 | 24 | assertEquals(metrics1, metrics2); 25 | assertNotEquals(metrics1, metrics3); 26 | 27 | assertEquals(metrics1.hashCode(), metrics2.hashCode()); 28 | assertNotEquals(metrics1.hashCode(), metrics3.hashCode()); 29 | } 30 | 31 | @Test 32 | public void testToString() { 33 | ClassMetrics metrics = new ClassMetrics(10, 20); 34 | String toStringResult = metrics.toString(); 35 | 36 | assertTrue(toStringResult.contains("offset=10")); 37 | assertTrue(toStringResult.contains("length=20")); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/ClassNotFoundRuntimeExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import net.openhft.chronicle.core.util.ClassNotFoundRuntimeException; 4 | import org.junit.jupiter.api.Test; 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | public class ClassNotFoundRuntimeExceptionTest { 8 | 9 | @Test 10 | public void testConstructor() { 11 | ClassNotFoundException cause = new ClassNotFoundException("Test class not found"); 12 | ClassNotFoundRuntimeException exception = new ClassNotFoundRuntimeException(cause); 13 | 14 | assertNotNull(exception); 15 | assertEquals(cause, exception.getCause()); 16 | } 17 | 18 | @Test 19 | public void testGetCause() { 20 | ClassNotFoundException cause = new ClassNotFoundException("Test class not found"); 21 | ClassNotFoundRuntimeException exception = new ClassNotFoundRuntimeException(cause); 22 | 23 | Throwable throwableCause = exception.getCause(); 24 | 25 | assertTrue(throwableCause instanceof ClassNotFoundException); 26 | assertEquals(cause, throwableCause); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/CompilerUtilsTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import java.lang.reflect.Method; 5 | import static org.mockito.Mockito.*; 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class CompilerUtilsTest { 9 | @Test 10 | void defineClassShouldThrowAssertionErrorForIllegalAccessException() { 11 | ClassLoader classLoader = mock(ClassLoader.class); 12 | String className = "com.example.MyClass"; 13 | byte[] bytes = new byte[] { /* class file bytes */ }; 14 | 15 | // Simulate IllegalAccessException 16 | assertThrows(AssertionError.class, () -> CompilerUtils.defineClass(classLoader, className, bytes)); 17 | } 18 | 19 | @Test 20 | void defineClassShouldThrowAssertionErrorForInvocationTargetException() { 21 | ClassLoader classLoader = mock(ClassLoader.class); 22 | String className = "com.example.MyClass"; 23 | byte[] bytes = new byte[] { /* class file bytes */ }; 24 | 25 | // Simulate InvocationTargetException 26 | assertThrows(AssertionError.class, () -> CompilerUtils.defineClass(classLoader, className, bytes)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/IgnoresEverythingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import net.openhft.chronicle.core.CoreTestCommon; 22 | import org.junit.Test; 23 | 24 | import java.util.function.Consumer; 25 | 26 | import static org.junit.Assert.assertTrue; 27 | 28 | public class IgnoresEverythingTest extends CoreTestCommon { 29 | @Test 30 | public void test() { 31 | assertTrue(Mocker.ignored(Consumer.class) instanceof IgnoresEverything); 32 | } 33 | 34 | @Test 35 | public void returnsIgnored() { 36 | assertTrue(Mocker.ignored(Chained.class).method1() instanceof IgnoresEverything); 37 | } 38 | 39 | interface Chained { 40 | Chained2 method1(); 41 | } 42 | 43 | interface Chained2 { 44 | Object method2(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/InvocationTargetRuntimeExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import org.junit.Ignore; 4 | import org.junit.Test; 5 | import java.lang.reflect.InvocationTargetException; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | public class InvocationTargetRuntimeExceptionTest { 10 | 11 | @Test 12 | public void testConstructorWithInvocationTargetException() { 13 | Exception targetException = new Exception("Target exception"); 14 | InvocationTargetException invocationCause = new InvocationTargetException(targetException); 15 | 16 | InvocationTargetRuntimeException exception = new InvocationTargetRuntimeException(invocationCause); 17 | 18 | assertEquals("The cause should be the target exception of the InvocationTargetException", 19 | targetException, exception.getCause()); 20 | } 21 | 22 | @Test 23 | public void testConstructorWithNonInvocationTargetException() { 24 | Exception nonInvocationCause = new Exception("Non-invocation exception"); 25 | 26 | InvocationTargetRuntimeException exception = new InvocationTargetRuntimeException(nonInvocationCause); 27 | 28 | assertEquals("The cause should be the non-invocation exception provided to the constructor", 29 | nonInvocationCause, exception.getCause()); 30 | } 31 | 32 | @Test 33 | @Ignore 34 | public void testConstructorWithNullCause() { 35 | InvocationTargetRuntimeException exception = new InvocationTargetRuntimeException(null); 36 | 37 | assertNull("The cause should be null", exception.getCause()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/MyClass.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | public class MyClass { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/SimpleCleanerTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import net.openhft.chronicle.core.util.SimpleCleaner; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.Assert.assertNotNull; 7 | import static org.mockito.Mockito.*; 8 | 9 | class SimpleCleanerTest { 10 | 11 | @Test 12 | void cleanShouldExecuteRunnableOnce() { 13 | Runnable runnable = mock(Runnable.class); 14 | SimpleCleaner cleaner = new SimpleCleaner(runnable); 15 | 16 | cleaner.clean(); 17 | cleaner.clean(); // Second call to check idempotency 18 | 19 | verify(runnable, times(1)).run(); 20 | } 21 | 22 | @Test 23 | void cleanShouldNotExecuteRunnableIfAlreadyCleaned() { 24 | Runnable runnable = mock(Runnable.class); 25 | SimpleCleaner cleaner = new SimpleCleaner(runnable); 26 | 27 | cleaner.clean(); // First call 28 | cleaner.clean(); // Second call 29 | 30 | verify(runnable, times(1)).run(); 31 | } 32 | 33 | @Test 34 | void constructorShouldInitializeWithProvidedRunnable() { 35 | Runnable runnable = mock(Runnable.class); 36 | SimpleCleaner cleaner = new SimpleCleaner(runnable); 37 | 38 | assertNotNull(cleaner); // Verifying that cleaner is initialized 39 | // Further tests can be performed if needed to check internal state 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/ThreadConfinementAsserterTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import java.util.concurrent.CountDownLatch; 5 | import java.util.concurrent.ExecutorService; 6 | import java.util.concurrent.Executors; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | class ThreadConfinementAsserterTest { 11 | 12 | @Test 13 | void assertThreadConfinedSameThread() { 14 | ThreadConfinementAsserter asserter = ThreadConfinementAsserter.createEnabled(); 15 | 16 | assertDoesNotThrow(asserter::assertThreadConfined); 17 | assertDoesNotThrow(asserter::assertThreadConfined); 18 | } 19 | 20 | @Test 21 | void assertThreadConfinedDifferentThreads() throws InterruptedException { 22 | ThreadConfinementAsserter asserter = ThreadConfinementAsserter.createEnabled(); 23 | CountDownLatch latch = new CountDownLatch(1); 24 | ExecutorService executorService = Executors.newSingleThreadExecutor(); 25 | 26 | assertDoesNotThrow(asserter::assertThreadConfined); 27 | 28 | executorService.execute(() -> { 29 | assertThrows(IllegalStateException.class, asserter::assertThreadConfined); 30 | latch.countDown(); 31 | }); 32 | 33 | latch.await(); 34 | executorService.shutdown(); 35 | } 36 | 37 | @Test 38 | void createShouldReturnCorrectTypeBasedOnAssertions() { 39 | // This test's behavior will depend on whether assertions are enabled in the JVM. 40 | ThreadConfinementAsserter asserter = ThreadConfinementAsserter.create(); 41 | // Perform tests based on whether assertions are enabled or not. 42 | } 43 | 44 | @Test 45 | void createEnabledShouldAlwaysReturnFunctionalAsserter() { 46 | ThreadConfinementAsserter asserter = ThreadConfinementAsserter.createEnabled(); 47 | assertNotNull(asserter); 48 | // Further testing of functionality. 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/ThrowingFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import net.openhft.chronicle.core.CoreTestCommon; 22 | import org.jetbrains.annotations.NotNull; 23 | import org.junit.Test; 24 | 25 | import java.io.BufferedReader; 26 | import java.io.FileReader; 27 | import java.io.IOException; 28 | import java.util.function.Function; 29 | 30 | import static org.junit.Assert.fail; 31 | 32 | public class ThrowingFunctionTest extends CoreTestCommon { 33 | @Test 34 | public void asFunction() throws Exception { 35 | @NotNull Function sc = ThrowingFunction.asFunction(s -> { 36 | try (@NotNull BufferedReader br = new BufferedReader(new FileReader(s))) { 37 | return br.readLine(); 38 | } 39 | }); 40 | 41 | try { 42 | fail(sc.apply("doesn't exists")); 43 | if (false) throw new IOException(); 44 | } catch (IOException e) { 45 | // expected 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/ThrowingSupplierTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import java.util.function.Supplier; 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class ThrowingSupplierTest { 8 | 9 | @Test 10 | void getShouldReturnResultWhenNoException() throws Exception { 11 | ThrowingSupplier throwingSupplier = () -> "test"; 12 | assertEquals("test", throwingSupplier.get()); 13 | } 14 | 15 | @Test 16 | void getShouldThrowException() { 17 | ThrowingSupplier throwingSupplier = () -> { throw new Exception("error"); }; 18 | Exception exception = assertThrows(Exception.class, throwingSupplier::get); 19 | assertEquals("error", exception.getMessage()); 20 | } 21 | 22 | @Test 23 | void asSupplierShouldReturnResultWhenNoException() { 24 | ThrowingSupplier throwingSupplier = () -> "test"; 25 | Supplier supplier = ThrowingSupplier.asSupplier(throwingSupplier); 26 | assertEquals("test", supplier.get()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/TypeOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import net.openhft.chronicle.core.CoreTestCommon; 22 | import org.junit.Test; 23 | 24 | import java.util.List; 25 | import java.util.function.BiFunction; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | 29 | public class TypeOfTest extends CoreTestCommon { 30 | 31 | @Test 32 | public void type() { 33 | assertEquals("java.util.List", 34 | new TypeOf>() { 35 | }.type().toString()); 36 | assertEquals("java.util.List", 37 | new TypeOf>() { 38 | }.type().toString()); 39 | assertEquals("java.util.List", 40 | new TypeOf>() { 41 | }.type().toString()); 42 | assertEquals("java.util.function.BiFunction, java.lang.Integer, java.lang.String>", 43 | new TypeOf, Integer, String>>() { 44 | }.type().toString()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/UnresolvedTypeTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import java.lang.reflect.Type; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class UnresolvedTypeTest { 9 | 10 | @Test 11 | void constructorShouldInitializeTypeName() { 12 | String expectedTypeName = "MyType"; 13 | UnresolvedType unresolvedType = new UnresolvedType(expectedTypeName); 14 | 15 | assertEquals(expectedTypeName, unresolvedType.getTypeName()); 16 | } 17 | 18 | @Test 19 | void factoryMethodShouldCreateUnresolvedType() { 20 | String expectedTypeName = "MyType"; 21 | Type type = UnresolvedType.of(expectedTypeName); 22 | 23 | assertTrue(type instanceof UnresolvedType); 24 | assertEquals(expectedTypeName, type.getTypeName()); 25 | } 26 | 27 | @Test 28 | void getTypeNameShouldReturnCorrectTypeName() { 29 | String expectedTypeName = "MyType"; 30 | UnresolvedType unresolvedType = new UnresolvedType(expectedTypeName); 31 | 32 | assertEquals(expectedTypeName, unresolvedType.getTypeName()); 33 | } 34 | 35 | @Test 36 | void toStringShouldReturnTypeName() { 37 | String expectedTypeName = "MyType"; 38 | UnresolvedType unresolvedType = new UnresolvedType(expectedTypeName); 39 | 40 | assertEquals(expectedTypeName, unresolvedType.toString()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/UpdaterTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class UpdaterTest { 9 | 10 | @Test 11 | void updateShouldModifyInputAsExpected() { 12 | Updater> appender = list -> list.add("newElement"); 13 | List myList = new ArrayList<>(); 14 | 15 | appender.update(myList); 16 | 17 | assertEquals(1, myList.size()); 18 | assertTrue(myList.contains("newElement")); 19 | } 20 | 21 | @Test 22 | void acceptShouldDelegateToUpdate() { 23 | Updater> appender = list -> list.add("newElement"); 24 | List myList = new ArrayList<>(); 25 | 26 | appender.accept(myList); // Using accept instead of update 27 | 28 | assertEquals(1, myList.size()); 29 | assertTrue(myList.contains("newElement")); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/util/WeakIdentityHashMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 chronicle.software 3 | * 4 | * https://chronicle.software 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package net.openhft.chronicle.core.util; 20 | 21 | import net.openhft.chronicle.core.CoreTestCommon; 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertTrue; 26 | 27 | public class WeakIdentityHashMapTest extends CoreTestCommon { 28 | @Test 29 | public void twoKeys() { 30 | String a1 = Character.toString('a'); 31 | String a2 = Character.toString('a'); 32 | WeakIdentityHashMap map = new WeakIdentityHashMap<>(); 33 | map.put(a1, 1); 34 | map.put(a2, 2); 35 | assertEquals(2, map.size()); 36 | map.clear(); 37 | assertTrue(map.isEmpty()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/values/IntValueTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.values; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | import org.mockito.Mockito; 6 | 7 | import static org.junit.jupiter.api.Assertions.*; 8 | import static org.mockito.Mockito.*; 9 | 10 | class IntValueTest { 11 | 12 | private IntValue intValue; 13 | 14 | @BeforeEach 15 | void setUp() { 16 | intValue = mock(IntValue.class); // Create a mock object of IntValue 17 | } 18 | 19 | @Test 20 | void testGetValue() { 21 | when(intValue.getValue()).thenReturn(10); // Setup the mock to return 10 22 | assertEquals(10, intValue.getValue()); 23 | } 24 | 25 | @Test 26 | void testSetValue() { 27 | doNothing().when(intValue).setValue(anyInt()); 28 | intValue.setValue(20); 29 | verify(intValue, times(1)).setValue(20); 30 | } 31 | 32 | @Test 33 | void testCloseAndIsClosed() { 34 | when(intValue.isClosed()).thenReturn(false, true); // Before and after close 35 | assertFalse(intValue.isClosed()); 36 | intValue.close(); 37 | assertTrue(intValue.isClosed()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/values/LongValueImpl.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.values; 2 | 3 | import net.openhft.chronicle.core.io.SimpleCloseable; 4 | 5 | public class LongValueImpl extends SimpleCloseable implements LongValue { 6 | private long value = 0; 7 | 8 | @Override 9 | public long getValue() throws IllegalStateException { 10 | return value; 11 | } 12 | 13 | @Override 14 | public void setValue(long value) throws IllegalStateException { 15 | this.value = value; 16 | } 17 | 18 | @Override 19 | public long addValue(long delta) throws IllegalStateException { 20 | return value += delta; 21 | } 22 | 23 | @Override 24 | public boolean compareAndSwapValue(long expected, long value) throws IllegalStateException { 25 | if (this.value == expected) { 26 | this.value = value; 27 | return true; 28 | } 29 | return false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/openhft/chronicle/core/values/LongValueTest.java: -------------------------------------------------------------------------------- 1 | package net.openhft.chronicle.core.values; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | import static org.junit.jupiter.api.Assertions.*; 6 | import static org.mockito.Mockito.*; 7 | 8 | class LongValueTest { 9 | 10 | private LongValue longValue; 11 | 12 | @BeforeEach 13 | void setUp() { 14 | longValue = mock(LongValue.class); // Creating a mock instance of LongValue 15 | } 16 | 17 | @Test 18 | void testGetValue() { 19 | when(longValue.getValue()).thenReturn(10L); // Setup the mock to return 10 20 | assertEquals(10L, longValue.getValue()); 21 | } 22 | 23 | @Test 24 | void testSetValue() { 25 | doNothing().when(longValue).setValue(anyLong()); 26 | longValue.setValue(20L); 27 | verify(longValue, times(1)).setValue(20L); 28 | } 29 | 30 | // Additional tests for other methods... 31 | 32 | @Test 33 | void testCloseAndIsClosed() { 34 | when(longValue.isClosed()).thenReturn(false, true); // Before and after close 35 | assertFalse(longValue.isClosed()); 36 | longValue.close(); 37 | assertTrue(longValue.isClosed()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/services/net.openhft.chronicle.core.ChronicleInitRunnable: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2022 chronicle.software 3 | # 4 | # https://chronicle.software 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | net.openhft.chronicle.core.ChronicleInitTest$ServiceLoaderInit 20 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/services/net.openhft.chronicle.core.cleaner.spi.ByteBufferCleanerService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2022 chronicle.software 3 | # 4 | # https://chronicle.software 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | net.openhft.chronicle.core.internal.cleaner.Jdk9ByteBufferCleanerService 20 | net.openhft.chronicle.core.internal.cleaner.ReflectionBasedByteBufferCleanerService 21 | -------------------------------------------------------------------------------- /src/test/resources/readFileManyTimes.txt: -------------------------------------------------------------------------------- 1 | Dummy data 2 | -------------------------------------------------------------------------------- /src/test/resources/sample.system.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016-2019 Chronicle Software Ltd 3 | # 4 | org.slf4j.simpleLogger.log.isDebug=DEBUG 5 | org.slf4j.simpleLogger.log.isInfo=INFO 6 | org.slf4j.simpleLogger.log.isWarn=WARN 7 | warnAndCloseIfNotClosed=TRUE 8 | -------------------------------------------------------------------------------- /src/test/resources/test.expiry-date: -------------------------------------------------------------------------------- 1 | 2010-10-10 2 | -------------------------------------------------------------------------------- /src/test/resources/test2.expiry-date: -------------------------------------------------------------------------------- 1 | 2055-10-10 2 | --------------------------------------------------------------------------------