< prev index next >

core/tests/org.openjdk.jmc.flightrecorder.test/src/test/java/org/openjdk/jmc/flightrecorder/test/MetadataEventLocationUpdateTest.java

Print this page




   9 import java.util.Set;
  10 
  11 import org.junit.Test;
  12 import org.openjdk.jmc.common.item.Aggregators;
  13 import org.openjdk.jmc.common.item.IAggregator;
  14 import org.openjdk.jmc.common.item.IItemCollection;
  15 import org.openjdk.jmc.common.item.IItemIterable;
  16 import org.openjdk.jmc.common.item.ItemFilters;
  17 import org.openjdk.jmc.flightrecorder.CouldNotLoadRecordingException;
  18 import org.openjdk.jmc.flightrecorder.JfrAttributes;
  19 import org.openjdk.jmc.flightrecorder.test.util.RecordingToolkit;
  20 import org.openjdk.jmc.flightrecorder.util.ChunkReader;
  21 
  22 /**
  23  * In an upcoming release (12 or 13) the metadata event cannot be counted on being the last event in
  24  * the chunk anymore. These tests make sure the parser still work.
  25  */
  26 public final class MetadataEventLocationUpdateTest {
  27         private static final int CHUNK_COUNT_FLUSH_RECORDINGS = 2;
  28         private static final int CHUNK_COUNT_METADATA_RECORDINGS = 1;
  29         private static final String[] TYPES_TO_CHECK = {"jdk.GCPhaseParallel", "jdk.CompilerInlining"}; //$NON-NLS-1$ //$NON-NLS-2$
  30         private static final String[] TYPES_TO_CHECK_FLUSH = {"jdk.ModuleExport", "jdk.BooleanFlag", "jdk.JavaMonitorWait"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  31 
  32         private static final long[] EXPECTED_COUNTS_CONTROL = {12584, 7283};
  33         private static final long[] EXPECTED_COUNTS_NEW = {27738, 6883};
  34 
  35         private static final long[] EXPECTED_COUNTS_FLUSH_CONTROL = {1512, 1500, 991};
  36         private static final long[] EXPECTED_COUNTS_FLUSH_INCREMENTAL = {1512, 1500, 860};
  37 
  38         private static final int EXPECTED_NUMBER_OF_TYPES_FLUSH_RECORDINGS = 133;
  39 
  40         private static final String RECORDING_METADATA_CONTROL = "metadata_control.jfr"; //$NON-NLS-1$
  41         private static final String RECORDING_METADATA_NEW = "metadata_new.jfr"; //$NON-NLS-1$
  42 
  43         private static final String RECORDING_FLUSH_METADATA = "flush_metadata.jfr"; //$NON-NLS-1$
  44         private static final String RECORDING_FLUSH_INCREMENTAL_METADATA = "flush_incremental_metadata.jfr"; //$NON-NLS-1$
  45 
  46         @Test
  47         public void testChunkSplitter() throws IOException, CouldNotLoadRecordingException {
  48                 // Should not be affected, but just for good measure
  49                 int controlFlushChunkCount = countChunks(ChunkReader
  50                                 .readChunks(RecordingToolkit.getNamedRecordingResource(RECORDING_FLUSH_INCREMENTAL_METADATA)));
  51                 int incrementalFlushChunkCount = countChunks(ChunkReader
  52                                 .readChunks(RecordingToolkit.getNamedRecordingResource(RECORDING_FLUSH_INCREMENTAL_METADATA)));
  53                 int controlMetadataChunkCount = countChunks(
  54                                 ChunkReader.readChunks(RecordingToolkit.getNamedRecordingResource(RECORDING_METADATA_CONTROL)));
  55                 int newMetadataChunkCount = countChunks(
  56                                 ChunkReader.readChunks(RecordingToolkit.getNamedRecordingResource(RECORDING_METADATA_NEW)));
  57 
  58                 assertEquals(CHUNK_COUNT_FLUSH_RECORDINGS, controlFlushChunkCount);
  59                 assertEquals(CHUNK_COUNT_FLUSH_RECORDINGS, incrementalFlushChunkCount);
  60                 assertEquals(CHUNK_COUNT_METADATA_RECORDINGS, controlMetadataChunkCount);
  61                 assertEquals(CHUNK_COUNT_METADATA_RECORDINGS, newMetadataChunkCount);
  62         }
  63 
  64         @Test
  65         public void testGetEventTypes() throws IOException, CouldNotLoadRecordingException {
  66                 IItemCollection controlEvents = RecordingToolkit.getNamedRecording(RECORDING_METADATA_CONTROL);
  67                 IItemCollection newEvents = RecordingToolkit.getNamedRecording(RECORDING_METADATA_NEW);
  68 
  69                 IAggregator<Set<String>, ?> distinctTypesAggregator = Aggregators.distinct(JfrAttributes.EVENT_TYPE_ID);
  70                 Set<String> controlTypes = controlEvents.getAggregate(distinctTypesAggregator);
  71                 Set<String> newTypes = newEvents.getAggregate(distinctTypesAggregator);
  72                 newTypes.removeAll(controlTypes);
  73                 // The new flush event should be the one remaining
  74                 assertTrue(newTypes.contains("jdk.Flush")); //$NON-NLS-1$
  75                 assertEquals(1, newTypes.size());
  76         }
  77 
  78         @Test
  79         public void testCountsInRecordings() throws IOException, CouldNotLoadRecordingException {
  80                 IItemCollection controlEvents = RecordingToolkit.getNamedRecording(RECORDING_METADATA_CONTROL);
  81                 IItemCollection newEvents = RecordingToolkit.getNamedRecording(RECORDING_METADATA_NEW);
  82                 for (int i = 0; i < TYPES_TO_CHECK.length; i++) {
  83                         String typeId = TYPES_TO_CHECK[i];
  84                         long countControl = controlEvents.apply(ItemFilters.type(typeId)).getAggregate(Aggregators.count())
  85                                         .longValue();
  86                         long countNew = newEvents.apply(ItemFilters.type(typeId)).getAggregate(Aggregators.count()).longValue();
  87                         assertEquals(EXPECTED_COUNTS_CONTROL[i], countControl);
  88                         assertEquals(EXPECTED_COUNTS_NEW[i], countNew);
  89                 }
  90         }
  91 
  92         @Test
  93         public void testCountsInFlushRecordings() throws IOException, CouldNotLoadRecordingException {
  94                 IItemCollection controlFlushEvents = RecordingToolkit.getNamedRecording(RECORDING_FLUSH_METADATA);




   9 import java.util.Set;
  10 
  11 import org.junit.Test;
  12 import org.openjdk.jmc.common.item.Aggregators;
  13 import org.openjdk.jmc.common.item.IAggregator;
  14 import org.openjdk.jmc.common.item.IItemCollection;
  15 import org.openjdk.jmc.common.item.IItemIterable;
  16 import org.openjdk.jmc.common.item.ItemFilters;
  17 import org.openjdk.jmc.flightrecorder.CouldNotLoadRecordingException;
  18 import org.openjdk.jmc.flightrecorder.JfrAttributes;
  19 import org.openjdk.jmc.flightrecorder.test.util.RecordingToolkit;
  20 import org.openjdk.jmc.flightrecorder.util.ChunkReader;
  21 
  22 /**
  23  * In an upcoming release (12 or 13) the metadata event cannot be counted on being the last event in
  24  * the chunk anymore. These tests make sure the parser still work.
  25  */
  26 public final class MetadataEventLocationUpdateTest {
  27         private static final int CHUNK_COUNT_FLUSH_RECORDINGS = 2;
  28         private static final int CHUNK_COUNT_METADATA_RECORDINGS = 1;
  29         private static final String[] TYPES_TO_CHECK = {"jdk.GCPhaseParallel", "jdk.CompilerInlining"};
  30         private static final String[] TYPES_TO_CHECK_FLUSH = {"jdk.ModuleExport", "jdk.BooleanFlag", "jdk.JavaMonitorWait"};
  31 
  32         private static final long[] EXPECTED_COUNTS_CONTROL = {12584, 7283};
  33         private static final long[] EXPECTED_COUNTS_NEW = {27738, 6883};
  34 
  35         private static final long[] EXPECTED_COUNTS_FLUSH_CONTROL = {1512, 1500, 991};
  36         private static final long[] EXPECTED_COUNTS_FLUSH_INCREMENTAL = {1512, 1500, 860};
  37 
  38         private static final int EXPECTED_NUMBER_OF_TYPES_FLUSH_RECORDINGS = 133;
  39 
  40         private static final String RECORDING_METADATA_CONTROL = "metadata_control.jfr";
  41         private static final String RECORDING_METADATA_NEW = "metadata_new.jfr";
  42 
  43         private static final String RECORDING_FLUSH_METADATA = "flush_metadata.jfr";
  44         private static final String RECORDING_FLUSH_INCREMENTAL_METADATA = "flush_incremental_metadata.jfr";
  45 
  46         @Test
  47         public void testChunkSplitter() throws IOException, CouldNotLoadRecordingException {
  48                 // Should not be affected, but just for good measure
  49                 int controlFlushChunkCount = countChunks(ChunkReader
  50                                 .readChunks(RecordingToolkit.getNamedRecordingResource(RECORDING_FLUSH_INCREMENTAL_METADATA)));
  51                 int incrementalFlushChunkCount = countChunks(ChunkReader
  52                                 .readChunks(RecordingToolkit.getNamedRecordingResource(RECORDING_FLUSH_INCREMENTAL_METADATA)));
  53                 int controlMetadataChunkCount = countChunks(
  54                                 ChunkReader.readChunks(RecordingToolkit.getNamedRecordingResource(RECORDING_METADATA_CONTROL)));
  55                 int newMetadataChunkCount = countChunks(
  56                                 ChunkReader.readChunks(RecordingToolkit.getNamedRecordingResource(RECORDING_METADATA_NEW)));
  57 
  58                 assertEquals(CHUNK_COUNT_FLUSH_RECORDINGS, controlFlushChunkCount);
  59                 assertEquals(CHUNK_COUNT_FLUSH_RECORDINGS, incrementalFlushChunkCount);
  60                 assertEquals(CHUNK_COUNT_METADATA_RECORDINGS, controlMetadataChunkCount);
  61                 assertEquals(CHUNK_COUNT_METADATA_RECORDINGS, newMetadataChunkCount);
  62         }
  63 
  64         @Test
  65         public void testGetEventTypes() throws IOException, CouldNotLoadRecordingException {
  66                 IItemCollection controlEvents = RecordingToolkit.getNamedRecording(RECORDING_METADATA_CONTROL);
  67                 IItemCollection newEvents = RecordingToolkit.getNamedRecording(RECORDING_METADATA_NEW);
  68 
  69                 IAggregator<Set<String>, ?> distinctTypesAggregator = Aggregators.distinct(JfrAttributes.EVENT_TYPE_ID);
  70                 Set<String> controlTypes = controlEvents.getAggregate(distinctTypesAggregator);
  71                 Set<String> newTypes = newEvents.getAggregate(distinctTypesAggregator);
  72                 newTypes.removeAll(controlTypes);
  73                 // The new flush event should be the one remaining
  74                 assertTrue(newTypes.contains("jdk.Flush"));
  75                 assertEquals(1, newTypes.size());
  76         }
  77 
  78         @Test
  79         public void testCountsInRecordings() throws IOException, CouldNotLoadRecordingException {
  80                 IItemCollection controlEvents = RecordingToolkit.getNamedRecording(RECORDING_METADATA_CONTROL);
  81                 IItemCollection newEvents = RecordingToolkit.getNamedRecording(RECORDING_METADATA_NEW);
  82                 for (int i = 0; i < TYPES_TO_CHECK.length; i++) {
  83                         String typeId = TYPES_TO_CHECK[i];
  84                         long countControl = controlEvents.apply(ItemFilters.type(typeId)).getAggregate(Aggregators.count())
  85                                         .longValue();
  86                         long countNew = newEvents.apply(ItemFilters.type(typeId)).getAggregate(Aggregators.count()).longValue();
  87                         assertEquals(EXPECTED_COUNTS_CONTROL[i], countControl);
  88                         assertEquals(EXPECTED_COUNTS_NEW[i], countNew);
  89                 }
  90         }
  91 
  92         @Test
  93         public void testCountsInFlushRecordings() throws IOException, CouldNotLoadRecordingException {
  94                 IItemCollection controlFlushEvents = RecordingToolkit.getNamedRecording(RECORDING_FLUSH_METADATA);


< prev index next >