use of org.apache.commons.collections.map.LinkedMap in project hadoop by apache.
the class TestShortCircuitCache method testShmBasedStaleness.
@Test(timeout = 60000)
public void testShmBasedStaleness() throws Exception {
BlockReaderTestUtil.enableShortCircuitShmTracing();
TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
Configuration conf = createShortCircuitConf("testShmBasedStaleness", sockDir);
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
cluster.waitActive();
DistributedFileSystem fs = cluster.getFileSystem();
final ShortCircuitCache cache = fs.getClient().getClientContext().getShortCircuitCache();
String TEST_FILE = "/test_file";
final int TEST_FILE_LEN = 8193;
final int SEED = 0xFADED;
DFSTestUtil.createFile(fs, new Path(TEST_FILE), TEST_FILE_LEN, (short) 1, SEED);
FSDataInputStream fis = fs.open(new Path(TEST_FILE));
int first = fis.read();
final ExtendedBlock block = DFSTestUtil.getFirstBlock(fs, new Path(TEST_FILE));
Assert.assertTrue(first != -1);
cache.accept(new CacheVisitor() {
@Override
public void visit(int numOutstandingMmaps, Map<ExtendedBlockId, ShortCircuitReplica> replicas, Map<ExtendedBlockId, InvalidToken> failedLoads, LinkedMap evictable, LinkedMap evictableMmapped) {
ShortCircuitReplica replica = replicas.get(ExtendedBlockId.fromExtendedBlock(block));
Assert.assertNotNull(replica);
Assert.assertTrue(replica.getSlot().isValid());
}
});
// Stop the Namenode. This will close the socket keeping the client's
// shared memory segment alive, and make it stale.
cluster.getDataNodes().get(0).shutdown();
cache.accept(new CacheVisitor() {
@Override
public void visit(int numOutstandingMmaps, Map<ExtendedBlockId, ShortCircuitReplica> replicas, Map<ExtendedBlockId, InvalidToken> failedLoads, LinkedMap evictable, LinkedMap evictableMmapped) {
ShortCircuitReplica replica = replicas.get(ExtendedBlockId.fromExtendedBlock(block));
Assert.assertNotNull(replica);
Assert.assertFalse(replica.getSlot().isValid());
}
});
cluster.shutdown();
sockDir.close();
}
use of org.apache.commons.collections.map.LinkedMap in project flink by apache.
the class FlinkKafkaConsumerBaseTest method checkUseFetcherWhenNoCheckpoint.
/**
* Tests that on snapshots, states and offsets to commit to Kafka are correct
*/
@SuppressWarnings("unchecked")
@Test
public void checkUseFetcherWhenNoCheckpoint() throws Exception {
FlinkKafkaConsumerBase<String> consumer = getConsumer(null, new LinkedMap(), true);
List<KafkaTopicPartition> partitionList = new ArrayList<>(1);
partitionList.add(new KafkaTopicPartition("test", 0));
consumer.setSubscribedPartitions(partitionList);
OperatorStateStore operatorStateStore = mock(OperatorStateStore.class);
TestingListState<Serializable> listState = new TestingListState<>();
when(operatorStateStore.getSerializableListState(Matchers.any(String.class))).thenReturn(listState);
StateInitializationContext initializationContext = mock(StateInitializationContext.class);
when(initializationContext.getOperatorStateStore()).thenReturn(operatorStateStore);
// make the context signal that there is no restored state, then validate that
when(initializationContext.isRestored()).thenReturn(false);
consumer.initializeState(initializationContext);
consumer.run(mock(SourceFunction.SourceContext.class));
}
use of org.apache.commons.collections.map.LinkedMap in project flink by apache.
the class FlinkKafkaConsumerBaseTest method ignoreCheckpointWhenNotRunning.
/**
* Tests that no checkpoints happen when the fetcher is not running.
*/
@Test
public void ignoreCheckpointWhenNotRunning() throws Exception {
@SuppressWarnings("unchecked") final AbstractFetcher<String, ?> fetcher = mock(AbstractFetcher.class);
FlinkKafkaConsumerBase<String> consumer = getConsumer(fetcher, new LinkedMap(), false);
OperatorStateStore operatorStateStore = mock(OperatorStateStore.class);
TestingListState<Tuple2<KafkaTopicPartition, Long>> listState = new TestingListState<>();
when(operatorStateStore.getOperatorState(Matchers.any(ListStateDescriptor.class))).thenReturn(listState);
consumer.snapshotState(new StateSnapshotContextSynchronousImpl(1, 1));
assertFalse(listState.get().iterator().hasNext());
consumer.notifyCheckpointComplete(66L);
}
use of org.apache.commons.collections.map.LinkedMap in project flink by apache.
the class FlinkKafkaConsumerBaseTest method checkRestoredCheckpointWhenFetcherNotReady.
/**
* Tests that no checkpoints happen when the fetcher is not running.
*/
@Test
public void checkRestoredCheckpointWhenFetcherNotReady() throws Exception {
OperatorStateStore operatorStateStore = mock(OperatorStateStore.class);
TestingListState<Serializable> listState = new TestingListState<>();
listState.add(Tuple2.of(new KafkaTopicPartition("abc", 13), 16768L));
listState.add(Tuple2.of(new KafkaTopicPartition("def", 7), 987654321L));
FlinkKafkaConsumerBase<String> consumer = getConsumer(null, new LinkedMap(), true);
when(operatorStateStore.getSerializableListState(Matchers.any(String.class))).thenReturn(listState);
StateInitializationContext initializationContext = mock(StateInitializationContext.class);
when(initializationContext.getOperatorStateStore()).thenReturn(operatorStateStore);
when(initializationContext.isRestored()).thenReturn(true);
consumer.initializeState(initializationContext);
consumer.open(new Configuration());
consumer.snapshotState(new StateSnapshotContextSynchronousImpl(17, 17));
// ensure that the list was cleared and refilled. while this is an implementation detail, we use it here
// to figure out that snapshotState() actually did something.
Assert.assertTrue(listState.isClearCalled());
Set<Serializable> expected = new HashSet<>();
for (Serializable serializable : listState.get()) {
expected.add(serializable);
}
int counter = 0;
for (Serializable serializable : listState.get()) {
assertTrue(expected.contains(serializable));
counter++;
}
assertEquals(expected.size(), counter);
}
use of org.apache.commons.collections.map.LinkedMap in project jackrabbit by apache.
the class ChildNodeEntries method ensureModifiable.
/**
* Ensures that the {@link #nameMap} and {@link #entries} map are
* modifiable.
*/
@SuppressWarnings("unchecked")
private void ensureModifiable() {
if (nameMap == Collections.EMPTY_MAP) {
nameMap = new HashMap<Name, Object>();
entries = new LinkedMap();
} else if (shared) {
entries = (LinkedMap) entries.clone();
nameMap = new HashMap<Name, Object>(nameMap);
for (Map.Entry<Name, Object> entry : nameMap.entrySet()) {
Object value = entry.getValue();
if (value instanceof List<?>) {
entry.setValue(new ArrayList<ChildNodeEntry>((List<ChildNodeEntry>) value));
}
}
shared = false;
}
}
Aggregations