/** * A short-hand method for creating a {@link Map} of key/value pairs where * keys are {@link String}s and values are {@link Object}s. * * @param targetMap the {@link Map} to put the objects into. * @param objects alternating key and value. * @return a Map with the entries supplied by {@code objects}. */ public static Map<String, Object> map( Map<String, Object> targetMap, Object... objects ) { return genericMap( targetMap, objects ); }
/** * A short-hand method for creating a {@link Map} of key/value pairs where * both keys and values are {@link String}s. * * @param strings alternating key and value. * @return a Map with the entries supplied by {@code strings}. */ public static Map<String, String> stringMap( String... strings ) { return genericMap( (Object[]) strings ); }
/** * A short-hand method for creating a {@link Map} of key/value pairs where * keys are {@link String}s and values are {@link Object}s. * * @param objects alternating key and value. * @return a Map with the entries supplied by {@code objects}. */ public static Map<String, Object> map( Object... objects ) { return genericMap( objects ); }
/** * A short-hand method for creating a {@link Map} of key/value pairs where * both keys and values are {@link String}s. * * @param targetMap the {@link Map} to put the objects into. * @param strings alternating key and value. * @return a Map with the entries supplied by {@code strings}. */ public static Map<String, String> stringMap( Map<String, String> targetMap, String... strings ) { return genericMap( targetMap, (Object[]) strings ); }
/** * A short-hand method for creating a {@link Map} of key/value pairs. * * @param objects alternating key and value. * @param <K> type of keys * @param <V> type of values * @return a Map with the entries supplied by {@code objects}. */ public static <K, V> Map<K, V> genericMap( Object... objects ) { return genericMap( new HashMap<K, V>(), objects ); }
@Override protected Representation dispatchPointProperty( Point property, String param ) { return new MapRepresentation( genericMap( new LinkedHashMap<>(), "type", property.getGeometryType(), "coordinates", property.getCoordinate(), "crs", property.getCRS() ) ); }
public static ControlledStep<?> stepWithStats( String name, int maxProcessors, Object... statisticsAltKeyAndValue ) { return stepWithStats( name, maxProcessors, MapUtil.genericMap( statisticsAltKeyAndValue ) ); }
@Test public void shouldAccessExampleMetaData() { EmbeddedProxySPI spi = mock( EmbeddedProxySPI.class ); final KernelTransactionImplementation transaction = mock( KernelTransactionImplementation.class ); when( transaction.getMetaData() ).thenReturn( genericMap( "username", "Igor" ) ); TxStateTransactionDataSnapshot transactionDataSnapshot = new TxStateTransactionDataSnapshot( state, spi, ops, transaction ); assertEquals( 1, transactionDataSnapshot.metaData().size() ); assertThat( "Expected metadata map to contain defined username", transactionDataSnapshot.metaData(), equalTo( genericMap( "username", "Igor" ) ) ); }
@Test void nonUniqueSamplingCancel() throws IOException { Terms terms = getTerms( "test", 1 ); Map<String,Terms> fieldTermsMap = MapUtil.genericMap( "0string", terms, "id", terms, "0string", terms ); IndexReaderStub indexReader = new IndexReaderStub( new SamplingFields( fieldTermsMap ) ); when( indexSearcher.getIndexReader() ).thenReturn( indexReader ); NonUniqueLuceneIndexSampler luceneIndexSampler = createSampler(); taskControl.cancel(); IndexNotFoundKernelException notFoundKernelException = assertThrows( IndexNotFoundKernelException.class, luceneIndexSampler::sampleIndex ); assertEquals( notFoundKernelException.getMessage(), "Index dropped while sampling." ); }
@Test public void showsRemovedRelationships() throws Exception { // Given state.relationshipDoDelete( 1L, 1, 1L, 2L ); state.relationshipDoDelete( 2L, 1, 1L, 1L ); ops.withRelationship( 1, 1, 1, 2 ); ops.withRelationship( 2, 1, 1, 1, genericMap( "key", Values.of( "p") ) ); // When & Then TxStateTransactionDataSnapshot snapshot = snapshot(); assertThat( idList( snapshot.deletedRelationships() ), equalTo( asList( 1L, 2L ) ) ); assertThat( single( snapshot.removedRelationshipProperties() ).key(), equalTo( "key" ) ); }
@Test void nonUniqueIndexSampling() throws Exception { Terms aTerms = getTerms( "a", 1 ); Terms idTerms = getTerms( "id", 2 ); Terms bTerms = getTerms( "b", 3 ); Map<String,Terms> fieldTermsMap = MapUtil.genericMap( "0string", aTerms, "id", idTerms, "0array", bTerms ); IndexReaderStub indexReader = new IndexReaderStub( new SamplingFields( fieldTermsMap ) ); indexReader.setElements( new String[4] ); when( indexSearcher.getIndexReader() ).thenReturn( indexReader ); assertEquals( new IndexSample( 4, 2, 4 ), createSampler().sampleIndex() ); }
@Test public void showsDeletedNodes() throws Exception { // Given state.nodeDoDelete( 1L ); state.nodeDoDelete( 2L ); int labelId = 15; when( tokenRead.nodeLabelName( labelId ) ).thenReturn( "label" ); ops.withNode( 1, new long[]{labelId}, genericMap( "key", Values.of( "p" ) ) ); ops.withNode( 2, NO_LABELS ); // When & Then TxStateTransactionDataSnapshot snapshot = snapshot(); assertThat( idList( snapshot.deletedNodes() ), equalTo( asList( 1L, 2L ) ) ); assertThat( single( snapshot.removedLabels() ).label().name(), equalTo( "label" ) ); assertThat( single( snapshot.removedNodeProperties() ).key(), equalTo( "key" ) ); }
@Test public void shouldListRemovedRelationshipProperties() throws Exception { // Given int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); Value prevValue = Values.of( "prevValue" ); state.relationshipDoRemoveProperty( 1L, propertyKeyId ); ops.withRelationship( 1, 0, 0, 0, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Relationship>> propertyEntries = snapshot().removedRelationshipProperties(); // Then PropertyEntry<Relationship> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
@Test public void shouldListRemovedNodeProperties() throws Exception { // Given int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); Value prevValue = Values.of( "prevValue" ); state.nodeDoRemoveProperty( 1L, propertyKeyId ); ops.withNode( 1, NO_LABELS, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Node>> propertyEntries = snapshot().removedNodeProperties(); // Then PropertyEntry<Node> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
@Test public void shouldGivePortConflictErrorWithPortNumberInIt() throws Throwable { // Given an occupied port int port = 16000; try ( ServerSocketChannel ignore = ServerSocketChannel.open().bind( new InetSocketAddress( "localhost", port ) ) ) { final ListenSocketAddress address = new ListenSocketAddress( "localhost", port ); // Expect exception.expect( PortBindException.class ); // When Map<BoltConnector,NettyServer.ProtocolInitializer> initializersMap = genericMap( new BoltConnector( "test" ), protocolOnAddress( address ) ); new NettyServer( new NamedThreadFactory( "mythreads" ), initializersMap, new ConnectorPortRegister(), NullLog.getInstance() ).start(); } }
@Test public void shouldListAddedNodePropertiesProperties() throws Exception { // Given int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); Value prevValue = Values.of( "prevValue" ); state.nodeDoChangeProperty( 1L, propertyKeyId, Values.of( "newValue" ) ); ops.withNode( 1, NO_LABELS, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Node>> propertyEntries = snapshot().assignedNodeProperties(); // Then PropertyEntry<Node> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.value(), equalTo( "newValue" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
@Test public void shouldListAddedRelationshipProperties() throws Exception { // Given Value prevValue = Values.of( "prevValue" ); int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); state.relationshipDoReplaceProperty( 1L, propertyKeyId, prevValue, Values.of( "newValue" ) ); ops.withRelationship( 1, 0, 0, 0, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Relationship>> propertyEntries = snapshot().assignedRelationshipProperties(); // Then PropertyEntry<Relationship> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.value(), equalTo( "newValue" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
@Test public void shouldRemoveViaConcurrentIndexUpdatesWhilePopulating() throws Exception { // GIVEN String value1 = "Mattias"; String value2 = "Jacob"; String value3 = "Stefan"; long node1 = createNode( map( name, value1 ), FIRST ); long node2 = createNode( map( name, value2 ), FIRST ); long node3 = createNode( map( name, value3 ), FIRST ); int propertyKeyId = getPropertyKeyForName( name ); NodeDeletingWriter populator = new NodeDeletingWriter( node2, propertyKeyId, value2, labelId ); IndexPopulationJob job = newIndexPopulationJob( populator, new FlippableIndexProxy(), EntityType.NODE, indexDescriptor( FIRST, name, false ) ); populator.setJob( job ); // WHEN job.run(); // THEN Map<Long, Object> expectedAdded = genericMap( node1, value1, node2, value2, node3, value3 ); assertEquals( expectedAdded, populator.added ); Map<Long, Object> expectedRemoved = genericMap( node2, value2 ); assertEquals( expectedRemoved, populator.removed ); }
@Test public void shouldNotAcceptNodeWithoutMatchingProperty() { // given node.withNode( 17, new long[0], genericMap( 7, stringValue( "wrong" ) ) ); NodeValueClientFilter filter = initializeFilter( IndexQuery.exists( 12 ) ); // when filter.next(); assertFalse( filter.acceptNode( 17, null ) ); filter.close(); // then assertEvents( initialize(), Event.NEXT, Event.CLOSE ); }
@Test public void shouldAcceptNodeWithMatchingProperty() { // given node.withNode( 17, new long[0], genericMap( 12, stringValue( "hello" ) ) ); NodeValueClientFilter filter = initializeFilter( IndexQuery.exists( 12 ) ); // when filter.next(); assertTrue( filter.acceptNode( 17, null ) ); filter.close(); // then assertEvents( initialize(), Event.NEXT, new Event.Node( 17, null ), Event.CLOSE ); }