Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@

package oap.logstream;

import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import lombok.SneakyThrows;
import oap.io.Closeables;
import oap.logstream.LogStreamProtocol.ProtocolVersion;
import oap.logstream.formats.rowbinary.RowBinaryInputStream;
import oap.logstream.formats.RowBinaryAssertion;
import oap.util.LinkedHashMaps;
import org.apache.commons.lang3.ArrayUtils;
import org.testng.Assert;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.util.ArrayList;
Expand Down Expand Up @@ -130,41 +127,23 @@ public void reset() {
}

@SneakyThrows
public List<List<Object>> asRowBinary( Predicate<LogId> filter, String... headers ) {
List<List<Object>> ret = new ArrayList<>();
public RowBinaryAssertion assertRowBinary( Predicate<LogId> filter ) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();

String[] headers = null;
byte[][] types = null;
for( LogId id : outputs.keySet() ) {
if( filter.test( id ) ) {
IntArrayList rows = new IntArrayList();
if( headers.length == 0 ) {
for( int i = 0; i < id.headers.length; i++ ) {
rows.add( i );
}
} else {
for( String header : headers ) {
int index = ArrayUtils.indexOf( id.headers, header );

Preconditions.checkArgument( index >= 0, "header " + header + " not found" );

rows.add( index );
}
}

ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( outputs.getOrDefault( id, new ByteArrayOutputStream() ).toByteArray() );
RowBinaryInputStream rowBinaryInputStream = new RowBinaryInputStream( byteArrayInputStream, id.headers, id.types );

List<Object> objects;
while( ( objects = rowBinaryInputStream.readRow() ) != null ) {
ArrayList<Object> filtered = new ArrayList<>();
for( int i : rows ) {
filtered.add( objects.get( i ) );
}

ret.add( filtered );
}
baos.write( outputs.getOrDefault( id, new ByteArrayOutputStream() ).toByteArray() );
headers = id.headers;
types = id.types;
}
}

return ret;
if( headers == null ) {
Assert.fail( "No logs found!" );
}

return RowBinaryAssertion.assertRowBinary( baos.toByteArray(), headers, types );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ public static RowBinaryAssertion assertRowBinary( byte[] bytes ) {
return assertRowBinary( new ByteArrayInputStream( bytes ) );
}

public static RowBinaryAssertion assertRowBinary( byte[] bytes, String[] headers, byte[][] types ) {
return assertRowBinary( new ByteArrayInputStream( bytes ), headers, types );
}

public static RowBinaryAssertion assertRowBinary( InputStream inputStream ) {
return new RowBinaryAssertion( new RowBinaryData( null, null, inputStream ) );
}

public static RowBinaryAssertion assertRowBinary( InputStream inputStream, String[] headers, byte[][] types ) {
return new RowBinaryAssertion( new RowBinaryData( headers, types, inputStream ) );
}

public static Row row( Object... cols ) {
return new Row( cols );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ public void testLog() {
logger.log( new TestData( "ff", "cc", 12, List.of( "1" ), null, Map.of( "map_val_long_as_int", 333L ) ), "prefix", Map.of(), "mylog" );
logger.log( new TestData( null, "dd", 44, null, List.of( "2" ), Map.of( "map_val_long_as_int", 1L ) ), "prefix", Map.of(), "mylog" );

List<List<Object>> bytes = memoryLoggerBackend.asRowBinary( _ -> true );

assertThat( bytes ).isEqualTo( List.of(
List.of( "ff", 12, "ff", List.of( "1" ), 333 ),
List.of( "", 44, "dd", List.of( "2" ), 1 )
) );
memoryLoggerBackend
.assertRowBinary( _ -> true )
.containsExactlyInAnyOrderEntriesOf(
List.of( "ff", 12, "ff", List.of( "1" ), 333 ),
List.of( "", 44, "dd", List.of( "2" ), 1 )
);
}

@Test
Expand Down Expand Up @@ -173,14 +173,10 @@ public void testOptimization() {

MutableObject<String[]> headers = new MutableObject<>();

List<List<Object>> bytes = memoryLoggerBackend.asRowBinary( lid -> {
headers.setValue( lid.headers );
return true;
} );

assertThat( headers.get() ).isEqualTo( new String[] {"a", "or", "b", "a2", "aa2", "b2"} );

assertThat( bytes ).isEqualTo( List.of( List.of( "a1", "a1", 1, "a2", "aa2", 2 ) ) );
memoryLoggerBackend
.assertRowBinary( lid -> true )
.containOnlyHeaders( "a", "or", "b", "a2", "aa2", "b2" )
.containsExactlyInAnyOrderEntriesOf( List.of( "a1", "a1", 1, "a2", "aa2", 2 ) );

assertThat( listener.javaCode )
.isEqualTo( "{{ /* model MODEL1 id a path a type STRING defaultValue '' */<java.lang.String>a ?? \"\" }}"
Expand Down Expand Up @@ -249,14 +245,10 @@ public void testOptimization2() {

MutableObject<String[]> headers = new MutableObject<>();

List<List<Object>> bytes = memoryLoggerBackend.asRowBinary( lid -> {
headers.setValue( lid.headers );
return true;
} );

assertThat( headers.get() ).isEqualTo( new String[] {"a", "a1", "a2", "aa2"} );

assertThat( bytes ).isEqualTo( List.of( List.of( "a1", "", "a2", "a2xaa2" ) ) );
memoryLoggerBackend
.assertRowBinary( lid -> true )
.containOnlyHeaders( "a", "a1", "a2", "aa2" )
.containsExactlyInAnyOrderEntriesOf( List.of( "a1", "", "a2", "a2xaa2" ) );

assertThat( listener.javaCode )
.isEqualTo( "{{ /* model MODEL1 id a path a type STRING defaultValue '' */<java.lang.String>a ?? \"\" }}"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</distributionManagement>

<properties>
<oap.project.version>25.6.10</oap.project.version>
<oap.project.version>25.6.11</oap.project.version>

<oap.deps.config.version>25.0.1</oap.deps.config.version>
<oap.deps.oap-teamcity.version>25.0.0</oap.deps.oap-teamcity.version>
Expand Down
Loading