public void ClearResetsSizeAndEffectivellyClears() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var allocation = context.GetMemory(DefaultBufferSize); using (var buffer = new UnmanagedWriteBuffer(context, allocation)) { Assert.Equal(buffer.SizeInBytes, 0); buffer.Write(AllocationsBatch, 0, AllocationsBatch.Length); Assert.Equal(buffer.SizeInBytes, AllocationsBatch.Length); buffer.Clear(); Assert.Equal(buffer.SizeInBytes, 0); byte[] outputBuffer = new byte[AllocationsBatch.Length]; for (var i = 0; i < outputBuffer.Length; i++) { outputBuffer[i] = 124; fixed(byte *outputBufferPtr = outputBuffer) buffer.CopyTo(outputBufferPtr); foreach (var b in outputBuffer) { Assert.Equal(b, 124); } } } }
public UnmanagedJsonParser(JsonOperationContext ctx, JsonParserState state, string debugTag) { _ctx = ctx; _state = state; _debugTag = debugTag; _unmanagedWriteBuffer = ctx.GetStream(JsonOperationContext.InitialStreamSize); }
public void CopyToWithAllocations() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var allocation = context.GetMemory(DefaultBufferSize); using (var buffer = new UnmanagedWriteBuffer(context, allocation)) { Assert.Equal(buffer.SizeInBytes, 0); buffer.Write(NoAllocationsBatch, 0, NoAllocationsBatch.Length); Assert.Equal(buffer.SizeInBytes, NoAllocationsBatch.Length); for (var i = 0; i < NoAllocationsBatch.Length; i++) { Assert.Equal(allocation.Address[i], NoAllocationsBatch[i]); } byte[] outputBuffer = new byte[NoAllocationsBatch.Length]; fixed(byte *outputBufferPtr = outputBuffer) buffer.CopyTo(outputBufferPtr); for (var i = 0; i < NoAllocationsBatch.Length; i++) { Assert.Equal(outputBuffer[i], NoAllocationsBatch[i]); } } } }
public void CopyToThrowsAfterDispose() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize)); buffer.Dispose(); var outputBuffer = new byte[DefaultBufferSize]; fixed(byte *outputBufferPtr = outputBuffer) { try { buffer.CopyTo(outputBufferPtr); Assert.False(true); } catch (ObjectDisposedException) { } catch (Exception) { Assert.False(true); } } } }
public void NewDocument() { _maybeBeforePreamble = true; var previous = _unmanagedWriteBuffer.SizeInBytes; _unmanagedWriteBuffer.Dispose(); _unmanagedWriteBuffer = _ctx.GetStream(previous); }
public void WriteThrowsAfterDispose() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize)); buffer.Dispose(); Assert.Throws(typeof(ObjectDisposedException), () => buffer.Write(AllocationsBatch, 0, AllocationsBatch.Length)); } }
public void RepeatedDisposeDoesNotThrow() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize)); Assert.False(buffer.IsDisposed); buffer.Dispose(); Assert.True(buffer.IsDisposed); buffer.Dispose(); Assert.True(buffer.IsDisposed); } }
public void WriteByteThrowsAfterDispose() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize)); buffer.Dispose(); #if DEBUG Assert.Throws(typeof(ObjectDisposedException), () => buffer.WriteByte(10)); #else Assert.Throws(typeof(NullReferenceException), () => buffer.WriteByte(10)); #endif } }
public void CopiedDisposedObjectRemainsDisposed() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize)); Assert.False(buffer.IsDisposed); buffer.Dispose(); Assert.True(buffer.IsDisposed); var bufferCopy = buffer; Assert.True(buffer.IsDisposed); Assert.True(bufferCopy.IsDisposed); } }
public void WriteSingleByteNoAllocations() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var allocation = context.GetMemory(2); using (var buffer = new UnmanagedWriteBuffer(context, allocation)) { Assert.Equal(buffer.SizeInBytes, 0); buffer.WriteByte(10); Assert.Equal(buffer.SizeInBytes, 1); Assert.Equal(allocation.Address[0], 10); } } }
protected override unsafe Document DirectGet(Lucene.Net.Documents.Document input, string id, DocumentFields fields, IState state) { var reduceValue = input.GetField(Constants.Documents.Indexing.Fields.ReduceKeyValueFieldName).GetBinaryValue(state); var allocation = _context.GetMemory(reduceValue.Length); UnmanagedWriteBuffer buffer = new UnmanagedWriteBuffer(_context, allocation); buffer.Write(reduceValue, 0, reduceValue.Length); var result = new BlittableJsonReaderObject(allocation.Address, reduceValue.Length, _context, buffer); return(new Document { Data = result }); }
public void WriteMultipleBytesNoAllocations() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var allocation = context.GetMemory(DefaultBufferSize); using (var buffer = new UnmanagedWriteBuffer(context, allocation)) { for (int i = 0; i < DefaultBufferSize - 1; i++) { Assert.Equal(buffer.SizeInBytes, i); buffer.WriteByte((byte)i); Assert.Equal(allocation.Address[i], (byte)i); Assert.Equal(buffer.SizeInBytes, i + 1); } } } }
public void WriteMultipleBytesInBatchWithAllocations() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var allocation = context.GetMemory(DefaultBufferSize); using (var buffer = new UnmanagedWriteBuffer(context, allocation)) { Assert.Equal(buffer.SizeInBytes, 0); buffer.Write(AllocationsBatch, 0, AllocationsBatch.Length); Assert.Equal(buffer.SizeInBytes, AllocationsBatch.Length); for (int i = 0; i < DefaultBufferSize; i++) { Assert.Equal(allocation.Address[i], AllocationsBatch[i]); } } } }
public void WriteMultipleBytesWithAllocations() { using (var context = JsonOperationContext.ShortTermSingleUse()) { var allocation = context.GetMemory(DefaultBufferSize); using (var buffer = new UnmanagedWriteBuffer(context, allocation)) { for (int i = 0; i < 2 * DefaultBufferSize; i++) { Assert.Equal(buffer.SizeInBytes, i); buffer.WriteByte((byte)i); Assert.Equal(buffer.SizeInBytes, i + 1); // We can't verify that anything after the allocation was actually put into the correct place if (i < DefaultBufferSize) { Assert.Equal(allocation.Address[i], (byte)i); } } } } }
public void EnsureSingleChunkDoesNotChangeSizeOrContentsWithAllocations() { using (var context = JsonOperationContext.ShortTermSingleUse()) { using (var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize))) { buffer.Write(AllocationsBatch, 0, AllocationsBatch.Length); buffer.EnsureSingleChunk(out byte *address, out int size); Assert.Equal(size, AllocationsBatch.Length); for (int i = 0; i < AllocationsBatch.Length; i++) { Assert.Equal(address[i], AllocationsBatch[i]); } var outputBuffer = new byte[AllocationsBatch.Length]; fixed(byte *outputBufferPtr = outputBuffer) buffer.CopyTo(outputBufferPtr); for (int i = 0; i < AllocationsBatch.Length; i++) Assert.Equal(outputBuffer[i], AllocationsBatch[i]); } } }
public HashCalculator(JsonOperationContext ctx) { _buffer = ctx.GetStream(JsonOperationContext.InitialStreamSize); }
public QueryHashCalculator(JsonOperationContext ctx) { _buffer = ctx.GetStream(); }
public HashCalculator(JsonOperationContext ctx) { _context = ctx ?? throw new ArgumentNullException(nameof(ctx)); _buffer = _context.GetStream(JsonOperationContext.InitialStreamSize); }