Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.io.File emptyFile(org.neo4j.io.fs.FileSystemAbstraction fs) throws java.io.IOException
        private File EmptyFile(FileSystemAbstraction fs)
        {
            File shortFile = _directory.file("empty");

            fs.DeleteFile(shortFile);
            fs.Create(shortFile).close();
            return(shortFile);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldShowServerMetrics() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldShowServerMetrics()
        {
            // Given
            File      metrics = Folder.file("metrics");
            NeoServer server  = EnterpriseServerBuilder.serverOnRandomPorts().usingDataDir(Folder.databaseDir().AbsolutePath).withProperty(MetricsSettings.metricsEnabled.name(), "true").withProperty(MetricsSettings.csvEnabled.name(), "true").withProperty(MetricsSettings.csvPath.name(), metrics.Path).withProperty(MetricsSettings.csvInterval.name(), "100ms").persistent().build();

            try
            {
                // when
                server.Start();

                string host = "http://localhost:" + server.BaseUri().Port + ServerSettings.rest_api_path.DefaultValue + "/transaction/commit";

                for (int i = 0; i < 5; i++)
                {
                    ClientResponse r = Client.create().resource(host).accept(APPLICATION_JSON).type(APPLICATION_JSON).post(typeof(ClientResponse), "{ 'statements': [ { 'statement': 'CREATE ()' } ] }");
                    assertEquals(200, r.Status);
                }

                // then
                AssertMetricsExists(metrics, ServerMetrics.THREAD_JETTY_ALL);
                AssertMetricsExists(metrics, ServerMetrics.THREAD_JETTY_IDLE);
            }
            finally
            {
                server.Stop();
            }
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createCommunityBufferedContextByDefault()
        internal virtual void CreateCommunityBufferedContextByDefault()
        {
            IdContextFactory  idContextFactory = IdContextFactoryBuilder.Of(_fs, _jobScheduler).build();
            DatabaseIdContext idContext        = idContextFactory.CreateIdContext("database");

            IdGeneratorFactory idGeneratorFactory = idContext.IdGeneratorFactory;

            assertThat(idContext.IdController, instanceOf(typeof(BufferedIdController)));
            assertThat(idGeneratorFactory, instanceOf(typeof(BufferingIdGeneratorFactory)));

            (( BufferingIdGeneratorFactory )idGeneratorFactory).initialize(() => mock(typeof(KernelTransactionsSnapshot)));
            idGeneratorFactory.Open(_testDirectory.file("a"), IdType.NODE, () => 0, 100).Dispose();
            idGeneratorFactory.Open(_testDirectory.file("b"), IdType.PROPERTY, () => 0, 100).Dispose();

            BufferingIdGeneratorFactory bufferedFactory = ( BufferingIdGeneratorFactory )idGeneratorFactory;

            assertThat(bufferedFactory.Get(IdType.NODE), instanceOf(typeof(IdGeneratorImpl)));
            assertThat(bufferedFactory.Get(IdType.PROPERTY), not(instanceOf(typeof(IdGeneratorImpl))));
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void verifyPageCacheLongArray() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void VerifyPageCacheLongArray()
        {
            PageCache pageCache = _pageCacheRule.getPageCache(_fs);
            PagedFile file      = pageCache.Map(_dir.file("file"), pageCache.PageSize(), CREATE, DELETE_ON_CLOSE);

            using (LongArray array = new PageCacheLongArray(file, COUNT, 0, 0))
            {
                VerifyBehaviour(array);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// For backwards-compatibility reasons, we support both PEM-encoded certificates *and* raw binary files containing
        /// the certificate data.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldLoadBinaryCertificates() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldLoadBinaryCertificates()
        {
            // Given
            SelfSignedCertificate cert = new SelfSignedCertificate("example.com");
            PkiUtils certs             = new PkiUtils();

            File cPath = _testDirectory.file("certificate");

            assertTrue(cPath.createNewFile());
            sbyte[] raw = certs.LoadCertificates(cert.certificate())[0].Encoded;

            using (FileChannel ch = FileChannel.open(cPath.toPath(), WRITE))
            {
                FileUtils.writeAll(ch, ByteBuffer.wrap(raw));
            }

            // When
            Certificate[] certificates = certs.LoadCertificates(cPath);

            // Then
            assertThat(certificates.Length, equalTo(1));
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWriteALogHeaderInAFile() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWriteALogHeaderInAFile()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File file = testDirectory.file("WriteLogHeader");
            File file = TestDirectory.file("WriteLogHeader");

            // when
            writeLogHeader(FileSystemRule.get(), file, _expectedLogVersion, _expectedTxId);

            // then
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] array = new byte[LOG_HEADER_SIZE];
            sbyte[] array = new sbyte[LOG_HEADER_SIZE];
            using (Stream stream = FileSystemRule.get().openAsInputStream(file))
            {
                int read = stream.Read(array, 0, array.Length);
                assertEquals(LOG_HEADER_SIZE, read);
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ByteBuffer result = ByteBuffer.wrap(array);
            ByteBuffer result = ByteBuffer.wrap(array);

            long encodedLogVersions = result.Long;

            assertEquals(encodeLogVersion(_expectedLogVersion), encodedLogVersions);

            sbyte logFormatVersion = decodeLogFormatVersion(encodedLogVersions);

            assertEquals(CURRENT_LOG_VERSION, logFormatVersion);

            long logVersion = decodeLogVersion(encodedLogVersions);

            assertEquals(_expectedLogVersion, logVersion);

            long txId = result.Long;

            assertEquals(_expectedTxId, txId);
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void letImporterDecideAboutDatabaseExistence() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void LetImporterDecideAboutDatabaseExistence()
        {
            File          report        = _testDir.file("report");
            Path          homeDir       = _testDir.directory("home").toPath();
            PrintStream   nullOutput    = new PrintStream(NULL_OUTPUT_STREAM);
            OutsideWorld  outsideWorld  = new RealOutsideWorld(nullOutput, nullOutput, new MemoryStream(new sbyte[0]));
            Path          confPath      = _testDir.directory("conf").toPath();
            ImportCommand importCommand = new ImportCommand(homeDir, confPath, outsideWorld);
            File          nodesFile     = CreateTextFile("nodes.csv", ":ID", "1", "2");

            string[] arguments = new string[] { "--mode=csv", "--database=existing.db", "--nodes=" + nodesFile.AbsolutePath, "--report-file=" + report.AbsolutePath };

            // First run an import so that a database gets created
            importCommand.Execute(arguments);

            // When
            ImporterFactory importerFactory = mock(typeof(ImporterFactory));
            Importer        importer        = mock(typeof(Importer));

            when(importerFactory.GetImporterForMode(any(), any(), any(), any())).thenReturn(importer);
            (new ImportCommand(homeDir, confPath, outsideWorld, importerFactory)).Execute(arguments);

            // Then no exception about database existence should be thrown
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void createSelfSignedCertificateWithCorrectPermissions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CreateSelfSignedCertificateWithCorrectPermissions()
        {
            assumeTrue(!SystemUtils.IS_OS_WINDOWS);

            PkiUtils certificates = new PkiUtils();

            certificates.CreateSelfSignedCertificate(TestDirectory.file("certificate"), TestDirectory.file("privateKey"), "localhost");

            PosixFileAttributes certificateAttributes = Files.getFileAttributeView(TestDirectory.file("certificate").toPath(), typeof(PosixFileAttributeView)).readAttributes();

            assertTrue(certificateAttributes.permissions().contains(PosixFilePermission.OWNER_READ));
            assertTrue(certificateAttributes.permissions().contains(PosixFilePermission.OWNER_WRITE));
            assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.OWNER_EXECUTE));

            assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.GROUP_READ));
            assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.GROUP_WRITE));
            assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.GROUP_EXECUTE));

            assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.OTHERS_READ));
            assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.OTHERS_WRITE));
            assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.OTHERS_EXECUTE));

            PosixFileAttributes privateKey = Files.getFileAttributeView(TestDirectory.file("privateKey").toPath(), typeof(PosixFileAttributeView)).readAttributes();

            assertTrue(privateKey.permissions().contains(PosixFilePermission.OWNER_READ));
            assertTrue(privateKey.permissions().contains(PosixFilePermission.OWNER_WRITE));
            assertFalse(privateKey.permissions().contains(PosixFilePermission.OWNER_EXECUTE));

            assertFalse(privateKey.permissions().contains(PosixFilePermission.GROUP_READ));
            assertFalse(privateKey.permissions().contains(PosixFilePermission.GROUP_WRITE));
            assertFalse(privateKey.permissions().contains(PosixFilePermission.GROUP_EXECUTE));

            assertFalse(privateKey.permissions().contains(PosixFilePermission.OTHERS_READ));
            assertFalse(privateKey.permissions().contains(PosixFilePermission.OTHERS_WRITE));
            assertFalse(privateKey.permissions().contains(PosixFilePermission.OTHERS_EXECUTE));
        }
Esempio n. 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldGiveAClearErrorIfTheArchiveAlreadyExists() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldGiveAClearErrorIfTheArchiveAlreadyExists()
        {
            Path directory = _testDirectory.directory("a-directory").toPath();
            Path archive   = _testDirectory.file("the-archive.dump").toPath();

            Files.write(archive, new sbyte[0]);
            FileAlreadyExistsException exception = assertThrows(typeof(FileAlreadyExistsException), () => (new Dumper()).dump(directory, directory, archive, GZIP, Predicates.alwaysFalse()));

            assertEquals(archive.ToString(), exception.Message);
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldStoreAByteAtBoundary() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldStoreAByteAtBoundary()
        {
            using (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction())
            {
                File workFile = TmpDir.file("a");
                fs.Mkdirs(TmpDir.directory());
                Stream @out = fs.OpenAsOutputStream(workFile, false);

                // When I write a byte[] that is larger than the internal buffer in
                // ChannelOutputStream..
                sbyte[] b = new sbyte[8097];
                b[b.Length - 1] = 7;
                @out.Write(b, 0, b.Length);
                @out.Flush();

                // Then it should get cleanly written and be readable
                Stream @in = fs.OpenAsInputStream(workFile);
                @in.skip(8096);
                assertEquals(7, @in.Read());
            }
        }
Esempio n. 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void arraysShouldCalculateCorrectLength() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ArraysShouldCalculateCorrectLength()
        {
            // given
            int[] value = new int[3];
            for (int i = 0; i < value.Length; i++)
            {
                value[i] = 100 + i;
            }
            ValueType valueType = ValueType.typeOf(value);
            PhysicalFlushableChannel channel = new PhysicalFlushableChannel(Fs.open(Directory.file("file"), OpenMode.READ_WRITE));

            // when
            int length = valueType.Length(value);

            valueType.Write(value, channel);

            // then
            int expected = 1 + Integer.BYTES + value.Length * Integer.BYTES;               // array data

            assertEquals(expected, length);
            assertEquals(expected, channel.Position());
        }
Esempio n. 12
0
        protected internal override Fixture <MuninnPageCache> CreateFixture()
        {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            return(base.CreateFixture().withFileSystemAbstraction(DefaultFileSystemAbstraction::new).withFileConstructor(pathname => Directory.file(pathname)));
        }
Esempio n. 13
0
 private void Validate(string fileByName)
 {
     Validators.RegexFileExists.validate(Directory.file(fileByName));
 }
Esempio n. 14
0
 private File IdGeneratorFile()
 {
     return(_testDirectory.file("testIdGenerator.id"));
 }