/** * final File expectedStatArchiveFile = new File(TestUtil.getResourcePath(getClass(), * "StatArchiveWriterReaderJUnitTest_" + this.testName.getMethodName() + "_expected.gfs")); */ public static void compareStatArchiveFiles(final File expectedStatArchiveFile, final File actualStatArchiveFile) throws IOException { assertThat(expectedStatArchiveFile).exists(); assertThat(actualStatArchiveFile.length()).isEqualTo(expectedStatArchiveFile.length()); assertThat(readBytes(actualStatArchiveFile)).isEqualTo(readBytes(expectedStatArchiveFile)); }
private static void verifySameContent(TestResponse response, File file) throws IOException { assertThat(IOUtils.toByteArray(response.getInputStream())).isEqualTo(FileUtils.readFileToByteArray(file)); } }
@Test public void decodeUncompressedAddressToBytesShouldReturnActualBytes() { long encodedAddress = 549755813697L; Integer value = Integer.MAX_VALUE; byte[] actual = OffHeapRegionEntryHelper.decodeUncompressedAddressToBytes(encodedAddress); byte[] expectedValue = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt(value).array(); assertThat(actual).isEqualTo(expectedValue); }
@Test public void decode() { assertThat(Hex.decode("41424344")).isEqualTo(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D' }); }
@Test public void testToByteArray() throws IOException { final byte[] expected = new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE}; final byte[] actual = IOUtils.toByteArray(new ByteArrayInputStream(expected)); assertThat(actual).isNotNull(); assertThat(actual.length).isEqualTo(expected.length); assertThat(actual).isEqualTo(expected); }
@Test public void newValueIsPdxInstanceUsesItsSerializedValue() throws Exception { PdxInstanceImpl newValue = mock(PdxInstanceImpl.class); when(event.basicGetNewValue()).thenReturn(newValue); byte[] bytes = new byte[] {0, 3, 4}; when(newValue.toBytes()).thenReturn(bytes); instance.serializeNewValueIfNeeded(region, event); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(event, times(1)).setCachedSerializedNewValue(captor.capture()); assertThat(captor.getValue()).isEqualTo(bytes); } }
@Test public void newValueIsCachedDeserializableUsesItsSerializedValue() { CachedDeserializable newValue = mock(CachedDeserializable.class); when(event.basicGetNewValue()).thenReturn(newValue); byte[] bytes = new byte[] {0, 3, 4}; when(newValue.getSerializedValue()).thenReturn(bytes); instance.serializeNewValueIfNeeded(region, event); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(event, times(1)).setCachedSerializedNewValue(captor.capture()); assertThat(captor.getValue()).isEqualTo(bytes); }
@Test public void encodedAddressShouldBeDecodableEvenIfValueIsUnserialized() { Integer value = Integer.MAX_VALUE; byte[] unSerializedValue = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt(value).array(); boolean isSerialized = false; boolean isCompressed = false; long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(unSerializedValue, isSerialized, isCompressed); byte[] actualValue = (byte[]) OffHeapRegionEntryHelper.decodeAddressToObject(encodedAddress); assertThat(actualValue).isEqualTo(unSerializedValue); }
@Test public void oldSecurityShouldSucceedIfAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); this.put65.cmdExecute(this.message, this.serverConnection, this.securityService, 0); ArgumentCaptor<byte[]> argument = ArgumentCaptor.forClass(byte[].class); verify(this.replyMessage).addBytesPart(argument.capture()); assertThat(argument.getValue()).isEqualTo(OK_BYTES); verify(this.authzRequest).putAuthorize(eq(REGION_NAME), eq(KEY), eq(VALUE), eq(true), eq(CALLBACK_ARG)); verify(this.replyMessage).send(this.serverConnection); }
@Test public void decodeCompressedDataAsAddressToRawBytes() { long encodedAddress = 549755813703L; byte[] expected = new byte[] {127, -1, -1, -1}; byte[] bytes = OffHeapRegionEntryHelper.decodeAddressToRawBytes(encodedAddress); assertThat(bytes).isEqualTo(expected); }
@Test public void returnsControlForCorrectOID() throws Exception { PasswordPolicyControlFactory ctrlFactory = new PasswordPolicyControlFactory(); Control control = mock(Control.class); when(control.getID()).thenReturn(PasswordPolicyControl.OID); when(control.getEncodedValue()).thenReturn( PasswordPolicyResponseControlTests.OPENLDAP_LOCKED_CTRL); Control result = ctrlFactory.getControlInstance(control); assertThat(result).isNotNull(); assertThat(PasswordPolicyResponseControlTests.OPENLDAP_LOCKED_CTRL).isEqualTo(result.getEncodedValue()); } }
@Test public void newValueIsSerializableUsesItsSerializedValue() { String newValue = "newValue"; when(event.basicGetNewValue()).thenReturn(newValue); instance.serializeNewValueIfNeeded(region, event); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(event, times(1)).setCachedSerializedNewValue(captor.capture()); assertThat(captor.getValue()).isEqualTo(EntryEventImpl.serialize(newValue)); }
@Test public void serializeToBlobWithNullReturnsBytesOfNull() throws Exception { byte[] bytes = serializeToBlob(null); assertThat(bytes).isNotNull().isEqualTo(this.bytesOfNull); }
@Test public void decodeUncompressedAddressToBytesShouldDecodeLongIfItsSerializedAndIfItsNotTooBig() { Long value = 0L; long encodedAddress = 123L; byte[] actual = OffHeapRegionEntryHelper.decodeUncompressedAddressToBytes(encodedAddress); byte[] expectedValue = EntryEventImpl.serialize(value); assertThat(actual).isEqualTo(expectedValue); }
@Test public void serializeNullToStreamWritesNullAsBytes() throws Exception { HeapDataOutputStream hdos = createHeapDataOutputStream(); serializeTo(null, hdos); assertThat(hdos.toByteArray()).isNotNull().isEqualTo(this.bytesOfNull); }
@Test public void serializeMapToStreamWritesMapAsBytes() throws Exception { HeapDataOutputStream hdos = createHeapDataOutputStream(); serializeTo(this.mapWithTwoEntries, hdos); assertThat(hdos.toByteArray()).isNotNull().isEqualTo(bytesOfMap); }
@Test public void writeUncompressed() throws Exception { final ByteBuf buf = GrpcTestUtil.requestByteBuf(); final ByteBufHttpData framed = framer.writePayload(buf); assertThat(framed.array()).isEqualTo(GrpcTestUtil.uncompressedFrame(GrpcTestUtil.requestByteBuf())); assertThat(buf.refCnt()).isEqualTo(0); framed.release(); }
@Test public void emptyNotCompressed() throws Exception { framer.setCompressor(new Gzip()); framer.setMessageCompression(true); final ByteBuf buf = GrpcTestUtil.protoByteBuf(SimpleRequest.getDefaultInstance()); assertThat(buf.readableBytes()).isEqualTo(0); final ByteBufHttpData framed = framer.writePayload(buf); assertThat(framed.array()).isEqualTo(GrpcTestUtil.uncompressedFrame( GrpcTestUtil.protoByteBuf(SimpleRequest.getDefaultInstance()))); assertThat(buf.refCnt()).isEqualTo(0); framed.release(); }
@Test public void compressed() throws Exception { framer.setCompressor(new Gzip()); framer.setMessageCompression(true); final ByteBuf buf = GrpcTestUtil.requestByteBuf(); final ByteBufHttpData framed = framer.writePayload(buf); assertThat(framed.array()).isEqualTo(GrpcTestUtil.compressedFrame(GrpcTestUtil.requestByteBuf())); assertThat(buf.refCnt()).isEqualTo(0); framed.release(); }
@Test public void getSerializedValueShouldSerializeTheValue() { Object regionEntryValue = getValue(); byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue); boolean isSerialized = false; boolean isCompressed = false; OffHeapStoredObject chunk = (OffHeapStoredObject) ma .allocateAndInitialize(regionEntryValueAsBytes, isSerialized, isCompressed); byte[] serializedValue = chunk.getSerializedValue(); assertThat(serializedValue).isEqualTo(EntryEventImpl.serialize(regionEntryValueAsBytes)); chunk.release(); }