-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathHeapVsNativeTest.java
More file actions
62 lines (54 loc) · 1.98 KB
/
Copy pathHeapVsNativeTest.java
File metadata and controls
62 lines (54 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0
*/
package net.openhft.chronicle.values.issue9;
import net.openhft.chronicle.bytes.Byteable;
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.values.MaxUtf8Length;
import net.openhft.chronicle.values.NotNull;
import net.openhft.chronicle.values.Values;
import net.openhft.chronicle.values.ValuesTestCommon;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests that heap and native {@link Entity} values hold the same content but
* do not return the original {@link String} instance when read back.
*/
public class HeapVsNativeTest extends ValuesTestCommon {
private static final String SYMBOL = "symbol";
/**
* Verifies the behaviour of a heap-backed {@link Entity} instance.
*/
@Test
public void heap() {
Entity entity = Values.newHeapInstance(Entity.class);
check(entity);
}
/**
* Exercises a native reference and checks it behaves like the heap variant.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void nativeRef() {
Entity entity = Values.newNativeReference(Entity.class);
byte[] bytes = new byte[7];
BytesStore<?, ?> bs = BytesStore.wrap(bytes);
Byteable byteable = (Byteable) entity;
byteable.bytesStore(bs, 0, bytes.length);
check(entity);
}
/**
* Common test logic that sets the symbol and ensures the stored sequence
* is equal in content but not identical to the input String.
*/
private void check(Entity entity) {
entity.setSymbol(SYMBOL);
assertTrue(SYMBOL.contentEquals(entity.getSymbol()));
assertNotEquals(SYMBOL, entity.getSymbol());
}
public interface Entity {
CharSequence getSymbol();
void setSymbol(@NotNull @MaxUtf8Length(6) CharSequence symbol);
}
}