@Override public boolean visit( StorageCommand element ) throws IOException { return ((Command)element).handle( this ); } }
@Override public boolean equals( Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } if ( !super.equals( o ) ) { return false; } IndexCommand that = (IndexCommand) o; return commandType == that.commandType && indexNameId == that.indexNameId && entityType == that.entityType && entityId == that.entityId && keyId == that.keyId && valueType == that.valueType && Objects.equals( value, that.value ); }
@Override public int hashCode() { return Objects.hash( super.hashCode(), commandType, indexNameId, entityType, entityId, keyId, valueType, value ); }
void writeDynamicRecords( WritableChannel channel, Iterable<DynamicRecord> records, int size ) throws IOException { channel.putInt( size ); // 4 for ( DynamicRecord record : records ) { writeDynamicRecord( channel, record ); } }
void writeDynamicRecords( WritableChannel channel, Collection<DynamicRecord> records ) throws IOException { writeDynamicRecords( channel, records, records.size() ); }
@SafeVarargs private final void addFiltered( Collection<StorageCommand> target, Mode mode, Command[]... commands ) { for ( Command[] c : commands ) { for ( Command command : c ) { if ( command.getMode() == mode ) { target.add( command ); } } } }
private void assertHandlesLogTruncation( Command cmd ) throws IOException { inMemoryChannel.reset(); writer.serialize( new PhysicalTransactionRepresentation( singletonList( cmd ) ) ); int bytesSuccessfullyWritten = inMemoryChannel.writerPosition(); try { LogEntry logEntry = logEntryReader.readLogEntry( inMemoryChannel ); StorageCommand command = ((LogEntryCommand) logEntry).getCommand(); assertEquals( cmd, command ); } catch ( Exception e ) { throw new AssertionError( "Failed to deserialize " + cmd.toString() + ", because: ", e ); } bytesSuccessfullyWritten--; while ( bytesSuccessfullyWritten-- > 0 ) { inMemoryChannel.reset(); writer.serialize( new PhysicalTransactionRepresentation( singletonList( cmd ) ) ); inMemoryChannel.truncateTo( bytesSuccessfullyWritten ); LogEntry deserialized = logEntryReader.readLogEntry( inMemoryChannel ); assertNull( "Deserialization did not detect log truncation!" + "Record: " + cmd + ", deserialized: " + deserialized, deserialized ); } }
@Override public int hashCode() { return Objects.hash( super.hashCode(), nextIndexNameId.get(), nextKeyId.get(), indexNameIdRange, keyIdRange, idToIndexName, idToKey ); }
void writeDynamicRecords( WritableChannel channel, Iterable<DynamicRecord> records, int size ) throws IOException { channel.putInt( size ); // 4 for ( DynamicRecord record : records ) { writeDynamicRecord( channel, record ); } }
void writeDynamicRecords( WritableChannel channel, Collection<DynamicRecord> records ) throws IOException { writeDynamicRecords( channel, records, records.size() ); }
@SafeVarargs private final void addFiltered( Collection<StorageCommand> target, Mode mode, Command[]... commands ) { for ( Command[] c : commands ) { for ( Command command : c ) { if ( command.getMode() == mode ) { target.add( command ); } } } }
@Override public boolean visit( StorageCommand element ) throws IOException { for ( TransactionApplier applier : appliers ) { if ( ((Command)element).handle( applier ) ) { return true; } } return false; }
@Override public int hashCode() { return Objects.hash( super.hashCode(), commandType, indexNameId, entityType, entityId, keyId, valueType, value ); }
@Override public boolean equals( Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } if ( !super.equals( o ) ) { return false; } IndexDefineCommand that = (IndexDefineCommand) o; return nextIndexNameId.get() == that.nextIndexNameId.get() && nextKeyId.get() == that.nextKeyId.get() && Objects.equals( indexNameIdRange, that.indexNameIdRange ) && Objects.equals( keyIdRange, that.keyIdRange ) && Objects.equals( idToIndexName, that.idToIndexName ) && Objects.equals( idToKey, that.idToKey ); }
@Test public void testVisit() throws Exception { Command cmd = mock( Command.class ); // WHEN boolean result = facade.visit( cmd ); // THEN InOrder inOrder = inOrder( cmd ); inOrder.verify( cmd ).handle( txApplier1 ); inOrder.verify( cmd ).handle( txApplier2 ); inOrder.verify( cmd ).handle( txApplier3 ); inOrder.verifyNoMoreInteractions(); assertFalse( result ); }
@Override public boolean matchesSafely( LogEntryCommand commandEntry ) { if ( commandEntry == null ) { return false; } Command command = (Command) commandEntry.getCommand(); return command.getKey() == key && command.getClass().equals( commandClass ); }
@Override public int hashCode() { return Objects.hash( super.hashCode(), nextIndexNameId.get(), nextKeyId.get(), indexNameIdRange, keyIdRange, idToIndexName, idToKey ); }
@Override public boolean equals( Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } if ( !super.equals( o ) ) { return false; } IndexCommand that = (IndexCommand) o; return commandType == that.commandType && indexNameId == that.indexNameId && entityType == that.entityType && entityId == that.entityId && keyId == that.keyId && valueType == that.valueType && Objects.equals( value, that.value ); }