Search in sources :

Example 1 with FakeStream

use of org.graylog2.buffers.processors.fakestreams.FakeStream in project graylog2-server by Graylog2.

the class SearchesIT method testCountWithFilter.

@Test
public void testCountWithFilter() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    final IndexSetConfig indexSetConfig = IndexSetConfig.builder().id("id").title("title").indexPrefix("prefix").shards(1).replicas(0).rotationStrategy(MessageCountRotationStrategyConfig.createDefault()).retentionStrategyClass(DeletionRetentionStrategy.class.getCanonicalName()).retentionStrategy(DeletionRetentionStrategyConfig.createDefault()).creationDate(ZonedDateTime.of(2017, 5, 24, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    final IndexSet indexSet = new TestIndexSet(indexSetConfig);
    final Stream stream = new FakeStream("test") {

        @Override
        public IndexSet getIndexSet() {
            return indexSet;
        }
    };
    when(streamService.load(STREAM_ID)).thenReturn(stream);
    CountResult result = searches.count("*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)), "streams:" + STREAM_ID);
    assertThat(result.count()).isEqualTo(5L);
}
Also used : TestIndexSet(org.graylog2.indexer.TestIndexSet) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) Stream(org.graylog2.plugin.streams.Stream) CountResult(org.graylog2.indexer.results.CountResult) IndexSet(org.graylog2.indexer.IndexSet) TestIndexSet(org.graylog2.indexer.TestIndexSet) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 2 with FakeStream

use of org.graylog2.buffers.processors.fakestreams.FakeStream in project graylog2-server by Graylog2.

the class MongoIndexSetServiceTest method deleteWithAssignedStreams.

@Test
@MongoDBFixtures("MongoIndexSetServiceTest.json")
public void deleteWithAssignedStreams() throws Exception {
    final IndexSetDeletedSubscriber subscriber = new IndexSetDeletedSubscriber();
    clusterEventBus.registerClusterEventSubscriber(subscriber);
    final FakeStream stream1 = new FakeStream("Test stream 1");
    final String streamId = "57f3d721a43c2d59cb750001";
    stream1.setIndexSetId(streamId);
    when(streamService.loadAllWithIndexSet(streamId)).thenReturn(Collections.singletonList(stream1));
    final int deletedEntries = indexSetService.delete(streamId);
    assertThat(deletedEntries).isEqualTo(0);
    assertThat(indexSetService.get(streamId)).isPresent();
    assertThat(indexSetService.findAll()).hasSize(3);
    assertThat(subscriber.getEvents()).isEmpty();
}
Also used : FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 3 with FakeStream

use of org.graylog2.buffers.processors.fakestreams.FakeStream in project graylog2-server by Graylog2.

the class PipelineFacadeTest method createNativeEntityWithDefaultStream.

@Test
public void createNativeEntityWithDefaultStream() throws NotFoundException {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.PIPELINE_V1).data(objectMapper.convertValue(PipelineEntity.create(ValueReference.of("Title"), ValueReference.of("Description"), ValueReference.of("pipeline \"Title\"\nstage 0 match either\nrule \"debug\"\nrule \"no-op\"\nend"), Collections.singleton(ValueReference.of(Stream.DEFAULT_STREAM_ID))), JsonNode.class)).build();
    final FakeStream fakeDefaultStream = new FakeStream("All message Fake") {

        @Override
        protected ObjectId getObjectId() {
            return new ObjectId(Stream.DEFAULT_STREAM_ID);
        }
    };
    when(streamService.load(Stream.DEFAULT_STREAM_ID)).thenReturn(fakeDefaultStream);
    final Map<EntityDescriptor, Object> nativeEntities = Collections.emptyMap();
    final NativeEntity<PipelineDao> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), nativeEntities, "username");
    assertThat(connectionsService.load(fakeDefaultStream.getId()).pipelineIds()).containsOnly(nativeEntity.entity().id());
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) PipelineEntity(org.graylog2.contentpacks.model.entities.PipelineEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) ObjectId(org.bson.types.ObjectId) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) Test(org.junit.Test)

Aggregations

FakeStream (org.graylog2.buffers.processors.fakestreams.FakeStream)3 Test (org.junit.Test)3 ZonedDateTime (java.time.ZonedDateTime)1 ObjectId (org.bson.types.ObjectId)1 PipelineDao (org.graylog.plugins.pipelineprocessor.db.PipelineDao)1 ElasticsearchBaseTest (org.graylog.testing.elasticsearch.ElasticsearchBaseTest)1 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)1 Entity (org.graylog2.contentpacks.model.entities.Entity)1 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)1 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)1 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)1 IndexSet (org.graylog2.indexer.IndexSet)1 TestIndexSet (org.graylog2.indexer.TestIndexSet)1 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)1 CountResult (org.graylog2.indexer.results.CountResult)1 Stream (org.graylog2.plugin.streams.Stream)1 DateTime (org.joda.time.DateTime)1