Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyAsyncActionCausesConcurrentFlushingRush(org.neo4j.function.ThrowingConsumer<CheckPointerImpl,java.io.IOException> asyncAction) throws Exception
        private void VerifyAsyncActionCausesConcurrentFlushingRush(ThrowingConsumer <CheckPointerImpl, IOException> asyncAction)
        {
            AtomicLong  limitDisableCounter = new AtomicLong();
            AtomicLong  observedRushCount   = new AtomicLong();
            BinaryLatch backgroundCheckPointStartedLatch = new BinaryLatch();
            BinaryLatch forceCheckPointStartLatch        = new BinaryLatch();

            _limiter = new IOLimiterAnonymousInnerClass4(this, limitDisableCounter, forceCheckPointStartLatch);

            MockTxIdStore();
            CheckPointerImpl checkPointer = checkPointer();

            doAnswer(invocation =>
            {
                backgroundCheckPointStartedLatch.Release();
                forceCheckPointStartLatch.Await();
                long newValue = limitDisableCounter.get();
                observedRushCount.set(newValue);
                return(null);
            }).when(_storageEngine).flushAndForce(_limiter);

            Future <object> forceCheckPointer = forkFuture(() =>
            {
                backgroundCheckPointStartedLatch.Await();
                asyncAction.Accept(checkPointer);
                return(null);
            });

            when(_threshold.isCheckPointingNeeded(anyLong(), eq(_info))).thenReturn(true);
            checkPointer.CheckPointIfNeeded(_info);
            forceCheckPointer.get();
            assertThat(observedRushCount.get(), @is(1L));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// In order to avoid browsers popping up an auth box when using the Neo4j Browser, it sends us a special header.
 /// When we get that special header, we send a crippled authentication challenge back that the browser does not
 /// understand, which lets the Neo4j Browser handle auth on its own.
 ///
 /// Otherwise, we send a regular basic auth challenge. This method adds the appropriate header depending on the
 /// inbound request.
 /// </summary>
 private static ThrowingConsumer <HttpServletResponse, IOException> RequestAuthentication(HttpServletRequest req, ThrowingConsumer <HttpServletResponse, IOException> responseGen)
 {
     if ("true".Equals(req.getHeader("X-Ajax-Browser-Auth")))
     {
         return(res =>
         {
             responseGen.Accept(res);
             res.addHeader(HttpHeaders.WWW_AUTHENTICATE, "None");
         });
     }
     else
     {
         return(res =>
         {
             responseGen.Accept(res);
             res.addHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"Neo4j\"");
         });
     }
 }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void runFailing(org.neo4j.function.ThrowingConsumer<SuspendableLifeCycle,Throwable> consumer) throws Throwable
        private void RunFailing(ThrowingConsumer <SuspendableLifeCycle, Exception> consumer)
        {
            try
            {
                consumer.Accept(_lifeCycle);
                fail();
            }
            catch (System.InvalidOperationException)
            {
            }
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void updateStore(final Store store, long transaction) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        private void UpdateStore(Store store, long transaction)
        {
            ThrowingConsumer <long, IOException> update = u =>
            {
                using (EntryUpdater <string> updater = store.Updater(u).get())
                {
                    updater.Apply("key " + u, Value("value " + u));
                }
            };

            update.Accept(transaction);
        }
Ejemplo n.º 5
0
 private void ForToken(ThrowingConsumer <Token, KernelException> f)
 {
     try
     {
         using (Transaction tx = beginTransaction())
         {
             f.Accept(tx.Token());
         }
     }
     catch (KernelException e)
     {
         fail("Unwanted exception: " + e.Message);
     }
 }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private byte[] createRunWith(org.neo4j.function.ThrowingConsumer<org.neo4j.bolt.messaging.Neo4jPack_Packer, java.io.IOException> valuePacker) throws java.io.IOException
        private sbyte[] CreateRunWith(ThrowingConsumer <Org.Neo4j.Bolt.messaging.Neo4jPack_Packer, IOException> valuePacker)
        {
            PackedOutputArray @out = new PackedOutputArray();

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = (new Neo4jPackV2()).newPacker(@out);

            packer.PackStructHeader(2, RunMessage.SIGNATURE);
            packer.Pack("RETURN $x");
            packer.PackMapHeader(1);
            packer.Pack("x");
            valuePacker.Accept(packer);

            return(@out.Bytes());
        }
Ejemplo n.º 7
0
 private void ForEachPopulation(ThrowingConsumer <IndexPopulation, Exception> action)
 {
     foreach (IndexPopulation population in Populations)
     {
         try
         {
             action.Accept(population);
         }
         catch (Exception failure)
         {
             Fail(population, failure);
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Iterate over some schema suppliers, and invoke a callback for every supplier that matches the node. To match the
        /// node N the supplier must supply a LabelSchemaDescriptor D, such that N has values for all the properties of D.
        /// The supplied schemas are all assumed to match N on label.
        /// <para>
        /// To avoid unnecessary store lookups, this implementation only gets propertyKeyIds for the node if some
        /// descriptor has a valid label.
        ///
        /// </para>
        /// </summary>
        /// @param <SUPPLIER> the type to match. Must implement SchemaDescriptorSupplier </param>
        /// @param <EXCEPTION> The type of exception that can be thrown when taking the action </param>
        /// <param name="schemaSuppliers"> The suppliers to match </param>
        /// <param name="specialPropertyId"> This property id will always count as a match for the descriptor, regardless of
        /// whether the node has this property or not </param>
        /// <param name="existingPropertyIds"> sorted array of property ids for the entity to match schema for. </param>
        /// <param name="callback"> The action to take on match </param>
        /// <exception cref="EXCEPTION"> This exception is propagated from the action </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static <SUPPLIER extends org.neo4j.internal.kernel.api.schema.SchemaDescriptorSupplier, EXCEPTION extends Exception> void onMatchingSchema(java.util.Iterator<SUPPLIER> schemaSuppliers, int specialPropertyId, int[] existingPropertyIds, org.neo4j.function.ThrowingConsumer<SUPPLIER,EXCEPTION> callback) throws EXCEPTION
        internal static void OnMatchingSchema <SUPPLIER, EXCEPTION>(IEnumerator <SUPPLIER> schemaSuppliers, int specialPropertyId, int[] existingPropertyIds, ThrowingConsumer <SUPPLIER, EXCEPTION> callback) where SUPPLIER : [email protected] where EXCEPTION : Exception
        {
            Debug.Assert(isSortedSet(existingPropertyIds));
            while (schemaSuppliers.MoveNext())
            {
                SUPPLIER         schemaSupplier = schemaSuppliers.Current;
                SchemaDescriptor schema         = schemaSupplier.schema();

                if (NodeHasSchemaProperties(existingPropertyIds, Schema.PropertyIds, specialPropertyId))
                {
                    callback.Accept(schemaSupplier);
                }
            }
        }
Ejemplo n.º 9
0
 private TimeoutHandler Renewing(ThrowingConsumer <Clock, Exception> action)
 {
     return(timeout =>
     {
         try
         {
             action.Accept(_clock);
         }
         catch (Exception e)
         {
             _log.error("Failed to process timeout.", e);
         }
         timeout.reset();
     });
 }
Ejemplo n.º 10
0
        private ThrowingFunction <CyclicBarrier, Node, Exception> MergeThen <T1>(ThrowingConsumer <T1> action) where T1 : Exception
        {
            return(barrier =>
            {
                using (Transaction tx = Db.beginTx())
                {
                    Node node = MergeNode();

                    barrier.await();

                    action.Accept(node);

                    tx.success();
                    return node;
                }
            });
        }
Ejemplo n.º 11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void withPopulator(IndexPopulator populator, org.neo4j.function.ThrowingConsumer<IndexPopulator,Exception> runWithPopulator, boolean closeSuccessfully) throws Exception
            internal virtual void WithPopulator(IndexPopulator populator, ThrowingConsumer <IndexPopulator, Exception> runWithPopulator, bool closeSuccessfully)
            {
                try
                {
                    populator.Create();
                    runWithPopulator.Accept(populator);
                    if (closeSuccessfully)
                    {
                        populator.ScanCompleted(Org.Neo4j.Kernel.Impl.Api.index.PhaseTracker_Fields.NullInstance);
                        TestSuite.consistencyCheck(populator);
                    }
                }
                finally
                {
                    populator.Close(closeSuccessfully);
                }
            }
Ejemplo n.º 12
0
 private void AssertIllegalToken(ThrowingConsumer <Token, KernelException> f)
 {
     try
     {
         using (Transaction tx = beginTransaction())
         {
             f.Accept(tx.Token());
             fail("Expected IllegalTokenNameException");
         }
     }
     catch (IllegalTokenNameException)
     {
         // wanted
     }
     catch (KernelException e)
     {
         fail("Unwanted exception: " + e.Message);
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Method for calling a lambda function on many objects when it is expected that the function might
        /// throw an exception. First exception will be thrown and subsequent will be suppressed.
        /// This method guarantees that all subjects will be consumed, unless <seealso cref="System.OutOfMemoryException"/> or some other serious error happens.
        /// </summary>
        /// <param name="consumer"> lambda function to call on each object passed </param>
        /// <param name="subjects"> <seealso cref="System.Collections.IEnumerable"/> of objects to call the function on </param>
        /// @param <E> the type of exception anticipated, inferred from the lambda </param>
        /// <exception cref="E"> if consumption fails with this exception </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static <T, E extends Exception> void safeForAll(org.neo4j.function.ThrowingConsumer<T,E> consumer, Iterable<T> subjects) throws E
        public static void SafeForAll <T, E>(ThrowingConsumer <T, E> consumer, IEnumerable <T> subjects) where E : Exception
        {
            E exception = null;

            foreach (T instance in subjects)
            {
                try
                {
                    consumer.Accept(instance);
                }
                catch (Exception e)
                {
                    exception = Exceptions.chain(exception, ( E )e);
                }
            }
            if (exception != null)
            {
                throw exception;
            }
        }