Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadNoKeyIdAsMinusOne() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadNoKeyIdAsMinusOne()
        {
            // GIVEN
            InMemoryClosableChannel channel     = new InMemoryClosableChannel();
            IndexDefineCommand      definitions = new IndexDefineCommand();
            int indexNameId = 10;

            definitions.Init(ObjectIntHashMap.newWithKeysValues("myindex", indexNameId), new ObjectIntHashMap <string>());
            definitions.Serialize(channel);
            IndexCommand.RemoveCommand removeCommand = new IndexCommand.RemoveCommand();
            removeCommand.Init(indexNameId, IndexEntityType.Node.id(), 1234, -1, null);
            removeCommand.Serialize(channel);

            // WHEN
            PhysicalLogCommandReaderV2_2_4 reader = new PhysicalLogCommandReaderV2_2_4();

            assertTrue(reader.Read(channel) is IndexDefineCommand);
            IndexCommand.RemoveCommand readRemoveCommand = (IndexCommand.RemoveCommand)reader.Read(channel);

            // THEN
            assertEquals(removeCommand.IndexNameId, readRemoveCommand.IndexNameId);
            assertEquals(removeCommand.EntityType, readRemoveCommand.EntityType);
            assertEquals(removeCommand.EntityId, readRemoveCommand.EntityId);
            assertEquals(removeCommand.KeyId, readRemoveCommand.KeyId);
            assertNull(removeCommand.Value);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void readRelationshipGroupCommandWithFixedReferenceFormat302() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReadRelationshipGroupCommandWithFixedReferenceFormat302()
        {
            // Given
            InMemoryClosableChannel channel = new InMemoryClosableChannel();
            RelationshipGroupRecord before  = new RelationshipGroupRecord(42, 3);

            before.UseFixedReferences = true;
            RelationshipGroupRecord after = new RelationshipGroupRecord(42, 3, 4, 5, 6, 7, 8, true);

            after.UseFixedReferences = true;

            (new Command.RelationshipGroupCommand(before, after)).Serialize(channel);

            // When
            PhysicalLogCommandReaderV3_0_2 reader = new PhysicalLogCommandReaderV3_0_2();
            Command command = reader.Read(channel);

            assertTrue(command is Command.RelationshipGroupCommand);

            Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand)command;

            // Then
            assertEquals(before, relationshipGroupCommand.Before);
            assertEquals(after, relationshipGroupCommand.After);
            assertTrue(relationshipGroupCommand.Before.UseFixedReferences);
            assertTrue(relationshipGroupCommand.After.UseFixedReferences);
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowExceptionWhenReadingIncompleteHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowExceptionWhenReadingIncompleteHeader()
        {
            // given
            long prevFileLastIndex = 1;
            long version           = 2;
            long prevIndex         = 3;
            long prevTerm          = 4;

            SegmentHeader           writtenHeader = new SegmentHeader(prevFileLastIndex, version, prevIndex, prevTerm);
            InMemoryClosableChannel channel       = new InMemoryClosableChannel();

            channel.PutLong(writtenHeader.Version());
            channel.PutLong(writtenHeader.PrevIndex());

            // when
            try
            {
                _marshal.unmarshal(channel);
                fail();
            }
            catch (EndOfStreamException)
            {
                // expected
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void nodeCommandWithFixedReferenceFormat302() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void NodeCommandWithFixedReferenceFormat302()
        {
            // Given
            InMemoryClosableChannel channel = new InMemoryClosableChannel();
            NodeRecord before = new NodeRecord(42, true, false, 33, 99, 66);
            NodeRecord after  = new NodeRecord(42, true, false, 33, 99, 66);

            before.UseFixedReferences = true;
            after.UseFixedReferences  = true;

            (new Command.NodeCommand(before, after)).Serialize(channel);

            // When
            PhysicalLogCommandReaderV3_0_2 reader = new PhysicalLogCommandReaderV3_0_2();
            Command command = reader.Read(channel);

            assertTrue(command is Command.NodeCommand);

            Command.NodeCommand nodeCommand = (Command.NodeCommand)command;

            // Then
            assertEquals(before, nodeCommand.Before);
            assertEquals(after, nodeCommand.After);
            assertTrue(nodeCommand.Before.UseFixedReferences);
            assertTrue(nodeCommand.After.UseFixedReferences);
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadIndexCommandHeaderCorrectly() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadIndexCommandHeaderCorrectly()
        {
            // This bug manifested in header byte[1] {0,1,2}, which contains:
            // [x   ,    ] start node needs long
            // [ x  ,    ] end node needs long
            // [  xx,xxxx] index name id
            // would have the mask for reading "start node needs long" to 0x8, where it should have been 0x80.
            // So we need an index name id which has the 0x8 bit set to falsely read that value as "true".
            // Number 12 will do just fine.

            // GIVEN
            PhysicalLogCommandReaderV2_2_4 reader  = new PhysicalLogCommandReaderV2_2_4();
            InMemoryClosableChannel        data    = new InMemoryClosableChannel();
            AddRelationshipCommand         command = new AddRelationshipCommand();
            sbyte  indexNameId = ( sbyte )12;
            long   entityId    = 123;
            sbyte  keyId       = ( sbyte )1;
            object value       = "test value";
            long   startNode   = 14;
            long   endNode     = 15;

            // WHEN
            command.Init(indexNameId, entityId, keyId, value, startNode, endNode);
            command.Serialize(data);

            // THEN
            AddRelationshipCommand readCommand = ( AddRelationshipCommand )reader.Read(data);

            assertEquals(indexNameId, readCommand.IndexNameId);
            assertEquals(entityId, readCommand.EntityId);
            assertEquals(keyId, readCommand.KeyId);
            assertEquals(value, readCommand.Value);
            assertEquals(startNode, readCommand.StartNode);
            assertEquals(endNode, readCommand.EndNode);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void readRelationshipGroupCommandWithNonRequiredSecondaryUnit() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReadRelationshipGroupCommandWithNonRequiredSecondaryUnit()
        {
            // Given
            InMemoryClosableChannel channel = new InMemoryClosableChannel();
            RelationshipGroupRecord before  = new RelationshipGroupRecord(42, 3);
            RelationshipGroupRecord after   = new RelationshipGroupRecord(42, 3, 4, 5, 6, 7, 8, true);

            after.RequiresSecondaryUnit = false;
            after.SecondaryUnitId       = 17;
            after.SetCreated();

            (new Command.RelationshipGroupCommand(before, after)).Serialize(channel);

            // When
            PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0();
            Command command = reader.Read(channel);

            assertTrue(command is Command.RelationshipGroupCommand);

            Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand)command;

            // Then
            assertEquals(before, relationshipGroupCommand.Before);
            assertEquals(after, relationshipGroupCommand.After);
            VerifySecondaryUnit(after, relationshipGroupCommand.After);
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailToWriteIndexDefineCommandIfMapIsLargerThanShort() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailToWriteIndexDefineCommandIfMapIsLargerThanShort()
        {
            // GIVEN
            InMemoryClosableChannel      channel  = new InMemoryClosableChannel(1000);
            IndexDefineCommand           command  = new IndexDefineCommand();
            MutableObjectIntMap <string> largeMap = InitMap(0xFFFF + 1);

            command.Init(largeMap, largeMap);

            // WHEN
            assertTrue(Serialize(channel, command));
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean serialize(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel channel, IndexDefineCommand command) throws java.io.IOException
        private bool Serialize(InMemoryClosableChannel channel, IndexDefineCommand command)
        {
            try
            {
                command.Serialize(channel);
            }
            catch (AssertionError)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWriteAndReadHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWriteAndReadHeader()
        {
            // given
            long prevFileLastIndex = 1;
            long version           = 2;
            long prevIndex         = 3;
            long prevTerm          = 4;

            SegmentHeader writtenHeader = new SegmentHeader(prevFileLastIndex, version, prevIndex, prevTerm);

            InMemoryClosableChannel channel = new InMemoryClosableChannel();

            // when
            _marshal.marshal(writtenHeader, channel);
            SegmentHeader readHeader = _marshal.unmarshal(channel);

            // then
            assertEquals(writtenHeader, readHeader);
        }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecreateSchemaRuleWhenDeleteCommandReadFromDisk() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecreateSchemaRuleWhenDeleteCommandReadFromDisk()
        {
            // GIVEN
            SchemaRecord beforeRecords = Serialize(_rule, _id, true, true);
            SchemaRecord afterRecords  = Serialize(_rule, _id, false, false);

            Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(beforeRecords, afterRecords, _rule);
            InMemoryClosableChannel   buffer  = new InMemoryClosableChannel();

            when(_neoStores.SchemaStore).thenReturn(_schemaStore);

            // WHEN
            command.Serialize(buffer);
            Command readCommand = _reader.read(buffer);

            // THEN
            assertThat(readCommand, instanceOf(typeof(Command.SchemaRuleCommand)));

            AssertSchemaRule((Command.SchemaRuleCommand)readCommand);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadRelationshipCommand() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadRelationshipCommand()
        {
            // Given
            InMemoryClosableChannel channel = new InMemoryClosableChannel();
            RelationshipRecord      before  = new RelationshipRecord(42, -1, -1, -1);
            RelationshipRecord      after   = new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, true, true);

            (new Command.RelationshipCommand(before, after)).Serialize(channel);

            // When
            PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0();
            Command command = reader.Read(channel);

            assertTrue(command is Command.RelationshipCommand);

            Command.RelationshipCommand relationshipCommand = (Command.RelationshipCommand)command;

            // Then
            assertEquals(before, relationshipCommand.Before);
            assertEquals(after, relationshipCommand.After);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void readRelationshipCommandWithNonRequiredSecondaryUnit() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReadRelationshipCommandWithNonRequiredSecondaryUnit()
        {
            InMemoryClosableChannel channel = new InMemoryClosableChannel();
            RelationshipRecord      before  = new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, true, true);

            before.RequiresSecondaryUnit = false;
            before.SecondaryUnitId       = 52;
            RelationshipRecord after = new RelationshipRecord(42, true, 1, 8, 3, 4, 5, 6, 7, true, true);

            (new Command.RelationshipCommand(before, after)).Serialize(channel);

            PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0();
            Command command = reader.Read(channel);

            assertTrue(command is Command.RelationshipCommand);

            Command.RelationshipCommand relationshipCommand = (Command.RelationshipCommand)command;
            assertEquals(before, relationshipCommand.Before);
            VerifySecondaryUnit(before, relationshipCommand.Before);
            assertEquals(after, relationshipCommand.After);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadSomeCommands() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadSomeCommands()
        {
            // GIVEN
            InMemoryClosableChannel channel = new InMemoryClosableChannel();

            Commands.CreateNode(0).serialize(channel);
            Commands.CreateNode(1).serialize(channel);
            Commands.CreateRelationshipTypeToken(0, 0).serialize(channel);
            Commands.CreateRelationship(0, 0, 1, 0).serialize(channel);
            Commands.CreatePropertyKeyToken(0, 0).serialize(channel);
            Commands.CreateProperty(0, PropertyType.SHORT_STRING, 0).serialize(channel);
            CommandReader reader = new PhysicalLogCommandReaderV3_0();

            // THEN
            assertTrue(reader.Read(channel) is Command.NodeCommand);
            assertTrue(reader.Read(channel) is Command.NodeCommand);
            assertTrue(reader.Read(channel) is Command.RelationshipTypeTokenCommand);
            assertTrue(reader.Read(channel) is Command.RelationshipCommand);
            assertTrue(reader.Read(channel) is Command.PropertyKeyTokenCommand);
            assertTrue(reader.Read(channel) is Command.PropertyCommand);
        }
Exemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProperlyMaskIndexIdFieldInIndexHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProperlyMaskIndexIdFieldInIndexHeader()
        {
            /* This is how the index command header is laid out
             * [x   ,    ] start node needs long
             * [ x  ,    ] end node needs long
             * [  xx,xxxx] index name id
             * This means that the index name id can be in the range of 0 to 63. This test verifies that
             * this constraint is actually respected
             */

            // GIVEN
            PhysicalLogCommandReaderV2_2_4 reader = new PhysicalLogCommandReaderV2_2_4();
            InMemoryClosableChannel        data   = new InMemoryClosableChannel();
            // Here we take advantage of the fact that all index commands have the same header written out
            AddRelationshipCommand command = new AddRelationshipCommand();
            long   entityId  = 123;
            sbyte  keyId     = ( sbyte )1;
            object value     = "test value";
            long   startNode = 14;
            long   endNode   = 15;

            for (sbyte indexByteId = 0; indexByteId < 63; indexByteId++)
            {
                // WHEN
                command.Init(indexByteId, entityId, keyId, value, startNode, endNode);
                command.Serialize(data);

                // THEN
                AddRelationshipCommand readCommand = ( AddRelationshipCommand )reader.Read(data);
                assertEquals(indexByteId, readCommand.IndexNameId);
                assertEquals(entityId, readCommand.EntityId);
                assertEquals(keyId, readCommand.KeyId);
                assertEquals(value, readCommand.Value);
                assertEquals(startNode, readCommand.StartNode);
                assertEquals(endNode, readCommand.EndNode);

                data.Reset();
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadNeoStoreCommand() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadNeoStoreCommand()
        {
            // Given
            InMemoryClosableChannel channel = new InMemoryClosableChannel();
            NeoStoreRecord          before  = new NeoStoreRecord();
            NeoStoreRecord          after   = new NeoStoreRecord();

            after.NextProp = 42;

            (new Command.NeoStoreCommand(before, after)).Serialize(channel);

            // When
            PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0();
            Command command = reader.Read(channel);

            assertTrue(command is Command.NeoStoreCommand);

            Command.NeoStoreCommand neoStoreCommand = (Command.NeoStoreCommand)command;

            // Then
            assertEquals(before.NextProp, neoStoreCommand.Before.NextProp);
            assertEquals(after.NextProp, neoStoreCommand.After.NextProp);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void readPropertyCommandWithNonRequiredSecondaryUnit() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReadPropertyCommandWithNonRequiredSecondaryUnit()
        {
            InMemoryClosableChannel channel = new InMemoryClosableChannel();
            PropertyRecord          before  = new PropertyRecord(1);
            PropertyRecord          after   = new PropertyRecord(2);

            after.RequiresSecondaryUnit = false;
            after.SecondaryUnitId       = 78;

            (new Command.PropertyCommand(before, after)).Serialize(channel);

            PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0();
            Command command = reader.Read(channel);

            assertTrue(command is Command.PropertyCommand);

            Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand)command;

            // Then
            assertEquals(before.NextProp, neoStoreCommand.Before.NextProp);
            assertEquals(after.NextProp, neoStoreCommand.After.NextProp);
            VerifySecondaryUnit(after, neoStoreCommand.After);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void readPropertyCommandWithFixedReferenceFormat302() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReadPropertyCommandWithFixedReferenceFormat302()
        {
            InMemoryClosableChannel channel = new InMemoryClosableChannel();
            PropertyRecord          before  = new PropertyRecord(1);
            PropertyRecord          after   = new PropertyRecord(2);

            before.UseFixedReferences = true;
            after.UseFixedReferences  = true;

            (new Command.PropertyCommand(before, after)).Serialize(channel);

            PhysicalLogCommandReaderV3_0_2 reader = new PhysicalLogCommandReaderV3_0_2();
            Command command = reader.Read(channel);

            assertTrue(command is Command.PropertyCommand);

            Command.PropertyCommand neoStoreCommand = (Command.PropertyCommand)command;

            // Then
            assertEquals(before.NextProp, neoStoreCommand.Before.NextProp);
            assertEquals(after.NextProp, neoStoreCommand.After.NextProp);
            assertTrue(neoStoreCommand.Before.UseFixedReferences);
            assertTrue(neoStoreCommand.After.UseFixedReferences);
        }