예제 #1
0
 public static IMatcher<int?> BetweenIncluding(int expectFrom, int expectTo)
 {
     return Matchers.Function((int? actual) => actual != null && actual >= expectFrom && actual <= expectTo, "an integer where " + expectFrom + " <= value <= " + expectTo);
 }
예제 #2
0
 public void ExpectTo_should_obtain_matcher()
 {
     Assert.IsInstanceOf <HaveKeyMatcher <int> >(Matchers.HaveKey(1));
 }
예제 #3
0
 public static IMatcher<int?> GreaterOrEqualTo(int expect)
 {
     return Matchers.Function((int? actual) => actual != null && actual >= expect, "an integer >= " + expect);
 }
예제 #4
0
 public static IMatcher<int?> Not(int expect)
 {
     return Matchers.Function((int? actual) => actual != null && actual != expect, "an integer != " + expect);
 }
예제 #5
0
 private Matcher <string> IndexRecoveryLogMatcher(string logMessage, string subIndexProviderKey)
 {
     return(Matchers.stringContainsInOrder(Iterables.asIterable(logMessage, "descriptor", "indexFile=", File.separator + subIndexProviderKey)));
 }
예제 #6
0
 public static IMatcher<int?> EqualTo(int expect)
 {
     return Matchers.Function((int? actual) => actual.Equals(expect), "an integer == " + expect);
 }
예제 #7
0
 protected override ITestMatcher <IEnumerable <T> > CreateMatcher <T>(IEnumerable <T> expected)
 {
     return(Matchers.BeSetEqualTo <T>(expected));
 }
        /// <exception cref="System.Exception"/>
        public virtual void TestOutOfOrder()
        {
            Log.Info("STARTING testOutOfOrder");
            AppContext   mockContext      = Org.Mockito.Mockito.Mock <AppContext>();
            EventHandler mockEventHandler = Org.Mockito.Mockito.Mock <EventHandler>();

            Org.Mockito.Mockito.When(mockContext.GetEventHandler()).ThenReturn(mockEventHandler
                                                                               );
            TestContainerLauncherImpl.ContainerManagementProtocolClient mockCM = Org.Mockito.Mockito.Mock
                                                                                 <TestContainerLauncherImpl.ContainerManagementProtocolClient>();
            TestContainerLauncherImpl.ContainerLauncherImplUnderTest ut = new TestContainerLauncherImpl.ContainerLauncherImplUnderTest
                                                                              (mockContext, mockCM);
            Configuration conf = new Configuration();

            ut.Init(conf);
            ut.Start();
            try
            {
                ContainerId             contId        = MakeContainerId(0l, 0, 0, 1);
                TaskAttemptId           taskAttemptId = MakeTaskAttemptId(0l, 0, 0, TaskType.Map, 0);
                string                  cmAddress     = "127.0.0.1:8000";
                StartContainersResponse startResp     = recordFactory.NewRecordInstance <StartContainersResponse
                                                                                         >();
                startResp.SetAllServicesMetaData(serviceResponse);
                Log.Info("inserting cleanup event");
                ContainerLauncherEvent mockCleanupEvent = Org.Mockito.Mockito.Mock <ContainerLauncherEvent
                                                                                    >();
                Org.Mockito.Mockito.When(mockCleanupEvent.GetType()).ThenReturn(ContainerLauncher.EventType
                                                                                .ContainerRemoteCleanup);
                Org.Mockito.Mockito.When(mockCleanupEvent.GetContainerID()).ThenReturn(contId);
                Org.Mockito.Mockito.When(mockCleanupEvent.GetTaskAttemptID()).ThenReturn(taskAttemptId
                                                                                         );
                Org.Mockito.Mockito.When(mockCleanupEvent.GetContainerMgrAddress()).ThenReturn(cmAddress
                                                                                               );
                ut.Handle(mockCleanupEvent);
                ut.WaitForPoolToIdle();
                Org.Mockito.Mockito.Verify(mockCM, Org.Mockito.Mockito.Never()).StopContainers(Matchers.Any
                                                                                               <StopContainersRequest>());
                Log.Info("inserting launch event");
                ContainerRemoteLaunchEvent mockLaunchEvent = Org.Mockito.Mockito.Mock <ContainerRemoteLaunchEvent
                                                                                       >();
                Org.Mockito.Mockito.When(mockLaunchEvent.GetType()).ThenReturn(ContainerLauncher.EventType
                                                                               .ContainerRemoteLaunch);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerID()).ThenReturn(contId);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetTaskAttemptID()).ThenReturn(taskAttemptId
                                                                                        );
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerMgrAddress()).ThenReturn(cmAddress
                                                                                              );
                Org.Mockito.Mockito.When(mockCM.StartContainers(Matchers.Any <StartContainersRequest
                                                                              >())).ThenReturn(startResp);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerToken()).ThenReturn(CreateNewContainerToken
                                                                                             (contId, cmAddress));
                ut.Handle(mockLaunchEvent);
                ut.WaitForPoolToIdle();
                Org.Mockito.Mockito.Verify(mockCM, Org.Mockito.Mockito.Never()).StartContainers(Matchers.Any
                                                                                                <StartContainersRequest>());
            }
            finally
            {
                ut.Stop();
            }
        }
예제 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void crashAndRebuildSlowWithDynamicStringDeletions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CrashAndRebuildSlowWithDynamicStringDeletions()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) new org.neo4j.test.TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabaseBuilder(testDir.databaseDir()).setConfig(org.neo4j.graphdb.factory.GraphDatabaseSettings.record_id_batch_size, "1").newGraphDatabase();
            GraphDatabaseAPI           db                 = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(Fs.get()).newImpermanentDatabaseBuilder(TestDir.databaseDir()).setConfig(GraphDatabaseSettings.record_id_batch_size, "1").newGraphDatabase();
            IList <long>               deletedNodeIds     = ProduceNonCleanDefraggedStringStore(db);
            IDictionary <IdType, long> highIdsBeforeCrash = GetHighIds(db);

            // Make sure all of our changes are actually written to the files, since any background flushing could
            // mess up the check-sums in non-deterministic ways
            Db.DependencyResolver.resolveDependency(typeof(PageCache)).flushAndForce();

            long checksumBefore  = Fs.get().checksum();
            long checksumBefore2 = Fs.get().checksum();

            assertThat(checksumBefore, Matchers.equalTo(checksumBefore2));

            EphemeralFileSystemAbstraction snapshot = Fs.snapshot(Db.shutdown);

            long snapshotChecksum = snapshot.Checksum();

            if (snapshotChecksum != checksumBefore)
            {
                using (Stream @out = new FileStream(TestDir.file("snapshot.zip"), FileMode.Create, FileAccess.Write))
                {
                    snapshot.DumpZip(@out);
                }
                using (Stream @out = new FileStream(TestDir.file("fs.zip"), FileMode.Create, FileAccess.Write))
                {
                    Fs.get().dumpZip(@out);
                }
            }
            assertThat(snapshotChecksum, equalTo(checksumBefore));

            // Recover with unsupported.dbms.id_generator_fast_rebuild_enabled=false
            AssertNumberOfFreeIdsEquals(TestDir.databaseDir(), snapshot, 0);
            GraphDatabaseAPI           newDb             = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(snapshot).newImpermanentDatabaseBuilder(TestDir.databaseDir()).setConfig(GraphDatabaseSettings.rebuild_idgenerators_fast, FALSE).newGraphDatabase();
            IDictionary <IdType, long> highIdsAfterCrash = GetHighIds(newDb);

            assertEquals(highIdsBeforeCrash, highIdsAfterCrash);

            try
            {
                using (Transaction tx = newDb.BeginTx())
                {
                    // Verify that the data we didn't delete is still around
                    int nameCount = 0;
                    int relCount  = 0;
                    foreach (Node node in newDb.AllNodes)
                    {
                        nameCount++;
                        assertThat(node, inTx(newDb, hasProperty("name"), true));
                        relCount += ( int )Iterables.count(node.GetRelationships(Direction.OUTGOING));
                    }

                    assertEquals(16, nameCount);
                    assertEquals(12, relCount);

                    // Verify that the ids of the nodes we deleted are reused
                    IList <long> newIds = new List <long>();
                    newIds.Add(newDb.CreateNode().Id);
                    newIds.Add(newDb.CreateNode().Id);
                    newIds.Add(newDb.CreateNode().Id);
                    newIds.Add(newDb.CreateNode().Id);
                    assertThat(newIds, @is(deletedNodeIds));
                    tx.Success();
                }
            }
            finally
            {
                newDb.Shutdown();
                snapshot.Dispose();
            }
        }
예제 #10
0
        /// <exception cref="System.Exception"/>
        private void TestTriggerBlockReport(bool incremental)
        {
            Configuration conf = new HdfsConfiguration();

            // Set a really long value for dfs.blockreport.intervalMsec and
            // dfs.heartbeat.interval, so that incremental block reports and heartbeats
            // won't be sent during this test unless they're triggered
            // manually.
            conf.SetLong(DFSConfigKeys.DfsBlockreportIntervalMsecKey, 10800000L);
            conf.SetLong(DFSConfigKeys.DfsHeartbeatIntervalKey, 1080L);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();

            cluster.WaitActive();
            FileSystem fs = cluster.GetFileSystem();
            DatanodeProtocolClientSideTranslatorPB spy = DataNodeTestUtils.SpyOnBposToNN(cluster
                                                                                         .GetDataNodes()[0], cluster.GetNameNode());

            DFSTestUtil.CreateFile(fs, new Path("/abc"), 16, (short)1, 1L);
            // We should get 1 incremental block report.
            Org.Mockito.Mockito.Verify(spy, Org.Mockito.Mockito.Timeout(60000).Times(1)).BlockReceivedAndDeleted
                (Matchers.Any <DatanodeRegistration>(), Matchers.AnyString(), Matchers.Any <StorageReceivedDeletedBlocks
                                                                                            []>());
            // We should not receive any more incremental or incremental block reports,
            // since the interval we configured is so long.
            for (int i = 0; i < 3; i++)
            {
                Sharpen.Thread.Sleep(10);
                Org.Mockito.Mockito.Verify(spy, Org.Mockito.Mockito.Times(0)).BlockReport(Matchers.Any
                                                                                          <DatanodeRegistration>(), Matchers.AnyString(), Matchers.Any <StorageBlockReport[]
                                                                                                                                                        >(), Org.Mockito.Mockito.AnyObject <BlockReportContext>());
                Org.Mockito.Mockito.Verify(spy, Org.Mockito.Mockito.Times(1)).BlockReceivedAndDeleted
                    (Matchers.Any <DatanodeRegistration>(), Matchers.AnyString(), Matchers.Any <StorageReceivedDeletedBlocks
                                                                                                []>());
            }
            // Create a fake block deletion notification on the DataNode.
            // This will be sent with the next incremental block report.
            ReceivedDeletedBlockInfo rdbi = new ReceivedDeletedBlockInfo(new Block(5678, 512,
                                                                                   1000), ReceivedDeletedBlockInfo.BlockStatus.DeletedBlock, null);
            DataNode       datanode    = cluster.GetDataNodes()[0];
            BPServiceActor actor       = datanode.GetAllBpOs()[0].GetBPServiceActors()[0];
            string         storageUuid = datanode.GetFSDataset().GetVolumes()[0].GetStorageID();

            actor.NotifyNamenodeDeletedBlock(rdbi, storageUuid);
            // Manually trigger a block report.
            datanode.TriggerBlockReport(new BlockReportOptions.Factory().SetIncremental(incremental
                                                                                        ).Build());
            // triggerBlockReport returns before the block report is
            // actually sent.  Wait for it to be sent here.
            if (incremental)
            {
                Org.Mockito.Mockito.Verify(spy, Org.Mockito.Mockito.Timeout(60000).Times(2)).BlockReceivedAndDeleted
                    (Matchers.Any <DatanodeRegistration>(), Matchers.AnyString(), Matchers.Any <StorageReceivedDeletedBlocks
                                                                                                []>());
            }
            else
            {
                Org.Mockito.Mockito.Verify(spy, Org.Mockito.Mockito.Timeout(60000)).BlockReport(Matchers.Any
                                                                                                <DatanodeRegistration>(), Matchers.AnyString(), Matchers.Any <StorageBlockReport[]
                                                                                                                                                              >(), Org.Mockito.Mockito.AnyObject <BlockReportContext>());
            }
            cluster.Shutdown();
        }
예제 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("WeakerAccess") public void assertBuffer(Object... writeEvents)
        public virtual void AssertBuffer(params object[] writeEvents)
        {
            assertThat(Buffer, Matchers.contains(writeEvents));
        }
예제 #12
0
 private void StubQueueAllocation(CSQueue queue, Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                  clusterResource, FiCaSchedulerNode node, int allocation, NodeType type)
 {
     // Simulate the queue allocation
     Org.Mockito.Mockito.DoAnswer(new _Answer_137(this, queue, allocation, node, clusterResource
                                                  , type)).When(queue).AssignContainers(Matchers.Eq(clusterResource), Matchers.Eq(
                                                                                            node), Matchers.Any <ResourceLimits>());
 }
예제 #13
0
 private ResourceLimits AnyResourceLimits()
 {
     return(Matchers.Any <ResourceLimits>());
 }
예제 #14
0
        public virtual void TestOffSwitchSchedulingMultiLevelQueues()
        {
            // Setup queue configs
            SetupMultiLevelQueues(csConf);
            //B3
            IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>();
            CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration
                                                        .Root, queues, queues, TestUtils.spyHook);
            // Setup some nodes
            int memoryPerNode        = 10;
            int coresPerNode         = 10;
            int numNodes             = 2;
            FiCaSchedulerNode node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, memoryPerNode
                                                             * Gb);
            FiCaSchedulerNode node_1 = TestUtils.GetMockNode("host_1", DefaultRack, 0, memoryPerNode
                                                             * Gb);

            Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource
                                                                              (numNodes * (memoryPerNode * Gb), numNodes * coresPerNode);
            Org.Mockito.Mockito.When(csContext.GetNumClusterNodes()).ThenReturn(numNodes);
            // Start testing
            LeafQueue b3 = (LeafQueue)queues[B3];
            LeafQueue b2 = (LeafQueue)queues[B2];

            // Simulate B3 returning a container on node_0
            StubQueueAllocation(b2, clusterResource, node_0, 0 * Gb, NodeType.OffSwitch);
            StubQueueAllocation(b3, clusterResource, node_0, 1 * Gb, NodeType.OffSwitch);
            root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource
                                                                              ));
            VerifyQueueMetrics(b2, 0 * Gb, clusterResource);
            VerifyQueueMetrics(b3, 1 * Gb, clusterResource);
            // Now, B2 should get the scheduling opportunity since B2=0G/2G, B3=1G/7G
            // also, B3 gets a scheduling opportunity since B2 allocates RACK_LOCAL
            StubQueueAllocation(b2, clusterResource, node_1, 1 * Gb, NodeType.RackLocal);
            StubQueueAllocation(b3, clusterResource, node_1, 1 * Gb, NodeType.OffSwitch);
            root.AssignContainers(clusterResource, node_1, new ResourceLimits(clusterResource
                                                                              ));
            InOrder allocationOrder = Org.Mockito.Mockito.InOrder(b2, b3);

            allocationOrder.Verify(b2).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                        <FiCaSchedulerNode>(), AnyResourceLimits());
            allocationOrder.Verify(b3).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                        <FiCaSchedulerNode>(), AnyResourceLimits());
            VerifyQueueMetrics(b2, 1 * Gb, clusterResource);
            VerifyQueueMetrics(b3, 2 * Gb, clusterResource);
            // Now, B3 should get the scheduling opportunity
            // since B2 has 1/2G while B3 has 2/7G,
            // However, since B3 returns off-switch, B2 won't get an opportunity
            StubQueueAllocation(b2, clusterResource, node_0, 1 * Gb, NodeType.NodeLocal);
            StubQueueAllocation(b3, clusterResource, node_0, 1 * Gb, NodeType.OffSwitch);
            root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource
                                                                              ));
            allocationOrder = Org.Mockito.Mockito.InOrder(b3, b2);
            allocationOrder.Verify(b3).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                        <FiCaSchedulerNode>(), AnyResourceLimits());
            allocationOrder.Verify(b2).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                        <FiCaSchedulerNode>(), AnyResourceLimits());
            VerifyQueueMetrics(b2, 1 * Gb, clusterResource);
            VerifyQueueMetrics(b3, 3 * Gb, clusterResource);
        }
예제 #15
0
 protected override ITestMatcher <IEnumerable <T> > CreateMatcher <T>(IEnumerable <T> expected, Comparison <T> comparison)
 {
     return(Matchers.BeSetEqualTo <T>(expected, comparison));
 }
예제 #16
0
 public void ExpectTo_should_obtain_matcher()
 {
     Assert.IsInstanceOf <HaveKeyWithValueMatcher <int, int> >(Matchers.HaveKeyWithValue(1, 2));
 }
예제 #17
0
 protected override ITestMatcher <T> CreateMatcher <T>(T expected)
 {
     return(Matchers.BeGreaterThan(expected));
 }
예제 #18
0
        public virtual void ExpectedTokenIsRetrievedFromDFS()
        {
            byte[] ident = new DelegationTokenIdentifier(new Text("owner"), new Text("renewer"
                                                                                     ), new Text("realuser")).GetBytes();
            byte[] pw      = new byte[] { 42 };
            Text   service = new Text(uri.ToString());

            // Create a token for the fetcher to fetch, wire NN to return it when asked
            // for this particular user.
            Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> t = new Org.Apache.Hadoop.Security.Token.Token
                                                                                   <DelegationTokenIdentifier>(ident, pw, FakeRenewer.Kind, service);
            Org.Mockito.Mockito.When(dfs.AddDelegationTokens(Matchers.Eq((string)null), Matchers.Any
                                                             <Credentials>())).ThenAnswer(new _Answer_77(service, t));
            Org.Mockito.Mockito.When(dfs.GetUri()).ThenReturn(uri);
            FakeRenewer.Reset();
            FileSystem fileSys = FileSystem.GetLocal(conf);

            try
            {
                DelegationTokenFetcher.Main(new string[] { "-fs", uri.ToString(), tokenFile });
                Path        p     = new Path(fileSys.GetWorkingDirectory(), tokenFile);
                Credentials creds = Credentials.ReadTokenStorageFile(p, conf);
                IEnumerator <Org.Apache.Hadoop.Security.Token.Token <object> > itr = creds.GetAllTokens
                                                                                         ().GetEnumerator();
                // make sure we got back exactly the 1 token we expected
                NUnit.Framework.Assert.IsTrue(itr.HasNext());
                NUnit.Framework.Assert.AreEqual(t, itr.Next());
                NUnit.Framework.Assert.IsTrue(!itr.HasNext());
                DelegationTokenFetcher.Main(new string[] { "--print", tokenFile });
                DelegationTokenFetcher.Main(new string[] { "--renew", tokenFile });
                NUnit.Framework.Assert.AreEqual(t, FakeRenewer.lastRenewed);
                FakeRenewer.Reset();
                DelegationTokenFetcher.Main(new string[] { "--cancel", tokenFile });
                NUnit.Framework.Assert.AreEqual(t, FakeRenewer.lastCanceled);
            }
            finally
            {
                fileSys.Delete(new Path(tokenFile), true);
            }
        }
예제 #19
0
 protected override ITestMatcher <T> CreateMatcher <T>(T expected, Comparison <T> comparison)
 {
     return(Matchers.BeGreaterThan(expected, comparison));
 }
예제 #20
0
 private Matcher <string> IndexRecoveryFinishedLogMatcher(string subIndexProviderKey)
 {
     return(Matchers.stringContainsInOrder(Iterables.asIterable("Schema index cleanup job finished", "descriptor", "indexFile=", File.separator + subIndexProviderKey, "Number of pages visited", "Number of cleaned crashed pointers", "Time spent")));
 }
예제 #21
0
        /// <exception cref="System.IO.IOException"/>
        private FSNamesystem MakeNameSystemSpy(Block block, INodeFile file)
        {
            Configuration conf  = new Configuration();
            FSImage       image = new FSImage(conf);

            DatanodeStorageInfo[] targets    = new DatanodeStorageInfo[] {  };
            FSNamesystem          namesystem = new FSNamesystem(conf, image);

            namesystem.SetImageLoaded(true);
            // set file's parent as root and put the file to inodeMap, so
            // FSNamesystem's isFileDeleted() method will return false on this file
            if (file.GetParent() == null)
            {
                INodeDirectory mparent = Org.Mockito.Mockito.Mock <INodeDirectory>();
                INodeDirectory parent  = new INodeDirectory(mparent.GetId(), new byte[0], mparent.
                                                            GetPermissionStatus(), mparent.GetAccessTime());
                parent.SetLocalName(new byte[0]);
                parent.AddChild(file);
                file.SetParent(parent);
            }
            namesystem.dir.GetINodeMap().Put(file);
            FSNamesystem namesystemSpy = Org.Mockito.Mockito.Spy(namesystem);
            BlockInfoContiguousUnderConstruction blockInfo = new BlockInfoContiguousUnderConstruction
                                                                 (block, (short)1, HdfsServerConstants.BlockUCState.UnderConstruction, targets);

            blockInfo.SetBlockCollection(file);
            blockInfo.SetGenerationStamp(genStamp);
            blockInfo.InitializeBlockRecovery(genStamp);
            Org.Mockito.Mockito.DoReturn(true).When(file).RemoveLastBlock(Matchers.Any <Block>
                                                                              ());
            Org.Mockito.Mockito.DoReturn(true).When(file).IsUnderConstruction();
            Org.Mockito.Mockito.DoReturn(new BlockInfoContiguous[1]).When(file).GetBlocks();
            Org.Mockito.Mockito.DoReturn(blockInfo).When(namesystemSpy).GetStoredBlock(Matchers.Any
                                                                                       <Block>());
            Org.Mockito.Mockito.DoReturn(blockInfo).When(file).GetLastBlock();
            Org.Mockito.Mockito.DoReturn(string.Empty).When(namesystemSpy).CloseFileCommitBlocks
                (Matchers.Any <INodeFile>(), Matchers.Any <BlockInfoContiguous>());
            Org.Mockito.Mockito.DoReturn(Org.Mockito.Mockito.Mock <FSEditLog>()).When(namesystemSpy
                                                                                      ).GetEditLog();
            return(namesystemSpy);
        }
예제 #22
0
 public static IMatcher<int?> GreaterThan(int expect)
 {
     return Matchers.Function((int? actual) => actual != null && actual > expect, "an integer > " + expect);
 }
 private DescriptorMatcher GetNativeMatcher(Matchers matcher)
 {
     switch (matcher)
     {
         case Matchers.L1:
             return new BFMatcher(DistanceType.L1);
         case Matchers.L2:
             return new BFMatcher(DistanceType.L2);
         case Matchers.L2Sqr:
             return new BFMatcher(DistanceType.L2Sqr);
         default:
             throw new ArgumentException("Don't know type " + matcher);
     }
 }
예제 #24
0
 public static IMatcher<int?> LessThanOrEqualTo(int expect)
 {
     return Matchers.Function((int? actual) => actual != null && actual <= expect, "an integer <= " + expect);
 }
예제 #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void givenClusterWhenMasterGoesDownAndTxIsRunningThenDontWaitToSwitch() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void GivenClusterWhenMasterGoesDownAndTxIsRunningThenDontWaitToSwitch()
        {
            ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory(TestName.MethodName))).withCluster(ClusterManager.clusterOfSize(3)).build();

            try
            {
                clusterManager.Start();
                ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
                cluster.Await(allSeesAllAsAvailable());

                HighlyAvailableGraphDatabase slave = cluster.AnySlave;

                Transaction tx = slave.BeginTx();
                // Do a little write operation so that all "write" aspects of this tx is initializes properly
                slave.CreateNode();

                // Shut down master while we're keeping this transaction open
                cluster.Shutdown(cluster.Master);

                cluster.Await(masterAvailable());
                cluster.Await(masterSeesSlavesAsAvailable(1));
                // Ending up here means that we didn't wait for this transaction to complete

                tx.Success();

                try
                {
                    tx.Close();
                    fail("Exception expected");
                }
                catch (Exception e)
                {
                    assertThat(e, instanceOf(typeof(TransientTransactionFailureException)));
                    Exception rootCause = rootCause(e);
                    assertThat(rootCause, instanceOf(typeof(TransactionTerminatedException)));
                    assertThat((( TransactionTerminatedException )rootCause).status(), Matchers.equalTo(Org.Neo4j.Kernel.Api.Exceptions.Status_General.DatabaseUnavailable));
                }
            }
            finally
            {
                clusterManager.Stop();
            }
        }
예제 #26
0
 public static IMatcher<int?> Between(int expectFrom, int expectTo)
 {
     return Matchers.Function((int? actual) => actual != null && actual > expectFrom && actual < expectTo, "an integer where " + expectFrom + " < value < " + expectTo);
 }
예제 #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testEntityCaching()
        public virtual void testEntityCaching()
        {
            string[] userIds = new string[] { "test" };
            // mock user and query
            User user = mock(typeof(User));

            when(user.Id).thenReturn(userIds[0]);
            when(user.FirstName).thenReturn("kermit");
            UserQuery userQuery = mock(typeof(UserQuery));

            when(userQuery.userIdIn(Matchers.anyVararg <string[]>())).thenReturn(userQuery);
            when(userQuery.listPage(anyInt(), anyInt())).thenReturn(Arrays.asList(user));
            when(processEngine.IdentityService.createUserQuery()).thenReturn(userQuery);

            // configure cache
            HalRelationCacheConfiguration configuration = new HalRelationCacheConfiguration();

            configuration.CacheImplementationClass = typeof(DefaultHalResourceCache);
            IDictionary <string, object> halUserConfig = new Dictionary <string, object>();

            halUserConfig["capacity"]      = 100;
            halUserConfig["secondsToLive"] = 10000;
            configuration.addCacheConfiguration(typeof(HalUser), halUserConfig);

            contextListener.configureCaches(configuration);

            // cache exists and is empty
            DefaultHalResourceCache cache = (DefaultHalResourceCache)Hal.Instance.getHalRelationCache(typeof(HalUser));

            assertNotNull(cache);
            assertEquals(0, cache.size());

            // get link resolver and resolve user
            HalLinkResolver linkResolver = Hal.Instance.getLinkResolver(typeof(UserRestService));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<org.camunda.bpm.engine.rest.hal.HalResource<?>> halUsers = linkResolver.resolveLinks(userIds, processEngine);
            IList <HalResource <object> > halUsers = linkResolver.resolveLinks(userIds, processEngine);

            // mocked user was resolved
            assertNotNull(halUsers);
            assertEquals(1, halUsers.Count);
            HalUser halUser = (HalUser)halUsers[0];

            assertEquals("kermit", halUser.FirstName);

            // cache contains user
            assertEquals(1, cache.size());

            // change user mock
            when(user.FirstName).thenReturn("fritz");

            // resolve users again
            halUsers = linkResolver.resolveLinks(userIds, processEngine);

            // cached mocked user was resolved with old name
            assertNotNull(halUsers);
            assertEquals(1, halUsers.Count);
            halUser = (HalUser)halUsers[0];
            assertEquals("kermit", halUser.FirstName);

            forwardTime(cache.SecondsToLive * 3);

            // resolve users again
            halUsers = linkResolver.resolveLinks(userIds, processEngine);

            // new mocked user was resolved with old name
            assertNotNull(halUsers);
            assertEquals(1, halUsers.Count);
            halUser = (HalUser)halUsers[0];
            assertEquals("fritz", halUser.FirstName);
        }
예제 #28
0
 public static IMatcher<int?> NotNull()
 {
     return Matchers.Function((int? actual) => actual != null, "a non null integer");
 }
예제 #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRunProcedure() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRunProcedure()
        {
            // Given
            NegotiateBoltV3();
            Connection.send(Util.chunk(new RunMessage("CREATE (n:Test {age: 2}) RETURN n.age AS age"), PullAllMessage.INSTANCE));

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.hamcrest.Matcher<java.util.Map<? extends String,?>> ageMatcher = hasEntry(is("fields"), equalTo(singletonList("age")));
            Matcher <IDictionary <string, ?> > ageMatcher = hasEntry(@is("fields"), equalTo(singletonList("age")));

            assertThat(Connection, Util.eventuallyReceives(msgSuccess(allOf(ageMatcher, hasKey("t_first"))), msgRecord(eqRecord(equalTo(longValue(2L)))), msgSuccess()));

            // When
            Connection.send(Util.chunk(new RunMessage("CALL db.labels() YIELD label"), PullAllMessage.INSTANCE));

            // Then
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.hamcrest.Matcher<java.util.Map<? extends String,?>> entryFieldsMatcher = hasEntry(is("fields"), equalTo(singletonList("label")));
            Matcher <IDictionary <string, ?> > entryFieldsMatcher = hasEntry(@is("fields"), equalTo(singletonList("label")));

            assertThat(Connection, Util.eventuallyReceives(msgSuccess(allOf(entryFieldsMatcher, hasKey("t_first"))), msgRecord(eqRecord(Matchers.equalTo(stringValue("Test")))), msgSuccess()));
        }
예제 #30
0
        /// <exception cref="System.IO.IOException"/>
        private static void SetHeartbeatResponse(DatanodeCommand[] cmds)
        {
            NNHAStatusHeartbeat ha = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState
                                                             .Active, fsImage.GetLastAppliedOrWrittenTxId());
            HeartbeatResponse response = new HeartbeatResponse(cmds, ha, null);

            Org.Mockito.Mockito.DoReturn(response).When(spyNN).SendHeartbeat((DatanodeRegistration
                                                                              )Matchers.Any(), (StorageReport[])Matchers.Any(), Matchers.AnyLong(), Matchers.AnyLong
                                                                                 (), Matchers.AnyInt(), Matchers.AnyInt(), Matchers.AnyInt(), (VolumeFailureSummary
                                                                                                                                               )Matchers.Any());
        }
예제 #31
0
        public virtual void TestMultiLevelQueues()
        {
            /*
             * Structure of queue:
             *            Root
             *           ____________
             *          /    |   \   \
             *         A     B    C   D
             *       / |   / | \   \
             *      A1 A2 B1 B2 B3  C1
             *                        \
             *                         C11
             *                           \
             *                           C111
             *                             \
             *                              C1111
             */
            // Setup queue configs
            SetupMultiLevelQueues(csConf);
            IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>();
            CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration
                                                        .Root, queues, queues, TestUtils.spyHook);
            // Setup some nodes
            int memoryPerNode        = 10;
            int coresPerNode         = 16;
            int numNodes             = 3;
            FiCaSchedulerNode node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, memoryPerNode
                                                             * Gb);
            FiCaSchedulerNode node_1 = TestUtils.GetMockNode("host_1", DefaultRack, 0, memoryPerNode
                                                             * Gb);
            FiCaSchedulerNode node_2 = TestUtils.GetMockNode("host_2", DefaultRack, 0, memoryPerNode
                                                             * Gb);

            Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource
                                                                              (numNodes * (memoryPerNode * Gb), numNodes * coresPerNode);
            Org.Mockito.Mockito.When(csContext.GetNumClusterNodes()).ThenReturn(numNodes);
            // Start testing
            CSQueue a  = queues[A];
            CSQueue b  = queues[B];
            CSQueue c  = queues[C];
            CSQueue d  = queues[D];
            CSQueue a1 = queues[A1];
            CSQueue a2 = queues[A2];
            CSQueue b1 = queues[B1];
            CSQueue b2 = queues[B2];
            CSQueue b3 = queues[B3];

            // Simulate C returning a container on node_0
            StubQueueAllocation(a, clusterResource, node_0, 0 * Gb);
            StubQueueAllocation(b, clusterResource, node_0, 0 * Gb);
            StubQueueAllocation(c, clusterResource, node_0, 1 * Gb);
            StubQueueAllocation(d, clusterResource, node_0, 0 * Gb);
            root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource
                                                                              ));
            VerifyQueueMetrics(a, 0 * Gb, clusterResource);
            VerifyQueueMetrics(b, 0 * Gb, clusterResource);
            VerifyQueueMetrics(c, 1 * Gb, clusterResource);
            VerifyQueueMetrics(d, 0 * Gb, clusterResource);
            Org.Mockito.Mockito.Reset(a);
            Org.Mockito.Mockito.Reset(b);
            Org.Mockito.Mockito.Reset(c);
            // Now get B2 to allocate
            // A = 0/3, B = 0/15, C = 1/6, D=0/6
            StubQueueAllocation(a, clusterResource, node_1, 0 * Gb);
            StubQueueAllocation(b2, clusterResource, node_1, 4 * Gb);
            StubQueueAllocation(c, clusterResource, node_1, 0 * Gb);
            root.AssignContainers(clusterResource, node_1, new ResourceLimits(clusterResource
                                                                              ));
            VerifyQueueMetrics(a, 0 * Gb, clusterResource);
            VerifyQueueMetrics(b, 4 * Gb, clusterResource);
            VerifyQueueMetrics(c, 1 * Gb, clusterResource);
            Org.Mockito.Mockito.Reset(a);
            Org.Mockito.Mockito.Reset(b);
            Org.Mockito.Mockito.Reset(c);
            // Now get both A1, C & B3 to allocate in right order
            // A = 0/3, B = 4/15, C = 1/6, D=0/6
            StubQueueAllocation(a1, clusterResource, node_0, 1 * Gb);
            StubQueueAllocation(b3, clusterResource, node_0, 2 * Gb);
            StubQueueAllocation(c, clusterResource, node_0, 2 * Gb);
            root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource
                                                                              ));
            InOrder allocationOrder = Org.Mockito.Mockito.InOrder(a, c, b);

            allocationOrder.Verify(a).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                       <FiCaSchedulerNode>(), AnyResourceLimits());
            allocationOrder.Verify(c).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                       <FiCaSchedulerNode>(), AnyResourceLimits());
            allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                       <FiCaSchedulerNode>(), AnyResourceLimits());
            VerifyQueueMetrics(a, 1 * Gb, clusterResource);
            VerifyQueueMetrics(b, 6 * Gb, clusterResource);
            VerifyQueueMetrics(c, 3 * Gb, clusterResource);
            Org.Mockito.Mockito.Reset(a);
            Org.Mockito.Mockito.Reset(b);
            Org.Mockito.Mockito.Reset(c);
            // Now verify max-capacity
            // A = 1/3, B = 6/15, C = 3/6, D=0/6
            // Ensure a1 won't alloc above max-cap although it should get
            // scheduling opportunity now, right after a2
            Log.Info("here");
            ((ParentQueue)a).SetMaxCapacity(.1f);
            // a should be capped at 3/30
            StubQueueAllocation(a1, clusterResource, node_2, 1 * Gb);
            // shouldn't be
            // allocated due
            // to max-cap
            StubQueueAllocation(a2, clusterResource, node_2, 2 * Gb);
            StubQueueAllocation(b3, clusterResource, node_2, 1 * Gb);
            StubQueueAllocation(b1, clusterResource, node_2, 1 * Gb);
            StubQueueAllocation(c, clusterResource, node_2, 1 * Gb);
            root.AssignContainers(clusterResource, node_2, new ResourceLimits(clusterResource
                                                                              ));
            allocationOrder = Org.Mockito.Mockito.InOrder(a, a2, a1, b, c);
            allocationOrder.Verify(a).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                       <FiCaSchedulerNode>(), AnyResourceLimits());
            allocationOrder.Verify(a2).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                        <FiCaSchedulerNode>(), AnyResourceLimits());
            allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                       <FiCaSchedulerNode>(), AnyResourceLimits());
            allocationOrder.Verify(c).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any
                                                       <FiCaSchedulerNode>(), AnyResourceLimits());
            VerifyQueueMetrics(a, 3 * Gb, clusterResource);
            VerifyQueueMetrics(b, 8 * Gb, clusterResource);
            VerifyQueueMetrics(c, 4 * Gb, clusterResource);
            Org.Mockito.Mockito.Reset(a);
            Org.Mockito.Mockito.Reset(b);
            Org.Mockito.Mockito.Reset(c);
        }