/// <summary> /// Constructor. /// </summary> /// <param name="target">Target.</param> /// <param name="marsh">Marshaller.</param> /// <param name="cacheName">Cache name.</param> /// <param name="keepBinary">Binary flag.</param> public DataStreamerImpl(IPlatformTargetInternal target, Marshaller marsh, string cacheName, bool keepBinary) : base(target) { _cacheName = cacheName; _keepBinary = keepBinary; // Create empty batch. _batch = new DataStreamerBatch <TK, TV>(); // Allocate GC handle so that this data streamer could be easily dereferenced from native code. WeakReference thisRef = new WeakReference(this); _hnd = marsh.Ignite.HandleRegistry.Allocate(thisRef); // Start topology listening. This call will ensure that buffer size member is updated. DoOutInOp(OpListenTopology, _hnd); // Membar to ensure fields initialization before leaving constructor. Thread.MemoryBarrier(); // Start flusher after everything else is initialized. _flusher = new Flusher <TK, TV>(thisRef); _flusher.RunThread(); }
public void OnExceptionIsExecutedWhenApiResultHasException() { Logger logger = new Logger(); ExceptionArgs exceptionArgs = null; FlushLogArgs flushArgs = FlushLogArgsFactory.Create(new[] { logger }); CreateRequestLogRequest request = PayloadFactory.Create(flushArgs); var kisslogApi = new Mock <IPublicApi>(); kisslogApi.Setup(p => p.CreateRequestLog(It.IsAny <CreateRequestLogRequest>(), It.IsAny <IEnumerable <File> >())) .Returns(new ApiResult <RequestLog> { Exception = new ApiException { ErrorMessage = $"Error {Guid.NewGuid()}" } }); FlushOptions options = new FlushOptions { UseAsync = false, OnException = (ExceptionArgs args) => { exceptionArgs = args; } }; Flusher.FlushAsync(options, kisslogApi.Object, flushArgs, request).ConfigureAwait(false); Assert.IsNotNull(exceptionArgs); }
public void ChangesFlushLogArgsFiles() { Logger logger = new Logger(); logger.LogAsFile("Content 1", "File1.txt"); logger.LogAsFile("Content 2", "File2.txt"); FlushLogArgs flushArgs = FlushLogArgsFactory.Create(new[] { logger }); IEnumerable <LoggedFile> files = flushArgs.Files; CreateRequestLogRequest request = PayloadFactory.Create(flushArgs); var kisslogApi = new Mock <IPublicApi>(); kisslogApi.Setup(p => p.CreateRequestLog(It.IsAny <CreateRequestLogRequest>(), It.IsAny <IEnumerable <File> >())) .Returns(new ApiResult <RequestLog>()); Flusher.FlushAsync(new FlushOptions { UseAsync = false }, kisslogApi.Object, flushArgs, request).ConfigureAwait(false); Assert.AreNotSame(files, flushArgs.Files); Assert.AreEqual(files.Count(), flushArgs.Files.Count()); logger.Reset(); }
public void CreatesACopyOfTheFilesAndDeletesThem(bool apiThrowsException) { Logger logger = new Logger(); logger.LogAsFile("Content 1", "File1.txt"); logger.LogAsFile("Content 2", "File2.txt"); FlushLogArgs flushArgs = FlushLogArgsFactory.Create(new[] { logger }); CreateRequestLogRequest request = PayloadFactory.Create(flushArgs); var kisslogApi = new Mock <IPublicApi>(); kisslogApi.Setup(p => p.CreateRequestLog(It.IsAny <CreateRequestLogRequest>(), It.IsAny <IEnumerable <File> >())).Callback(() => { if (apiThrowsException) { throw new Exception(); } }) .Returns(new ApiResult <RequestLog>()); Flusher.FlushAsync(new FlushOptions { UseAsync = false }, kisslogApi.Object, flushArgs, request).ConfigureAwait(false); IEnumerable <LoggedFile> flushArgsFiles = flushArgs.Files; IEnumerable <LoggedFile> loggerFiles = logger.DataContainer.FilesContainer.GetLoggedFiles(); foreach (var file in flushArgsFiles) { Assert.IsFalse(System.IO.File.Exists(file.FilePath)); } foreach (var file in loggerFiles) { Assert.IsTrue(System.IO.File.Exists(file.FilePath)); } logger.Reset(); }