@@ -513,8 +513,81 @@ static void test_dlq_disabled_no_copy(void)
513513 test_cleanup_with_cio (ctx , root );
514514}
515515
516+ static void test_dlq_restores_chunk_state_when_initially_down (void )
517+ {
518+ char root [256 ], rejdir [256 ];
519+ struct flb_config * ctx = NULL ;
520+ struct cio_chunk * src = NULL ;
521+ int rc ;
522+ const char * payload = "{\"msg\":\"state-restore-down\"}\n" ;
523+
524+ tmpdir_for (root , sizeof (root ), "restore-down" );
525+ snprintf (rejdir , sizeof (rejdir ), "%s/%s" , root , "rejected" );
526+ mkpath (rejdir );
527+
528+ ctx = make_ctx_fs (root , "rejected" );
529+
530+ /* Create the chunk */
531+ src = make_src_chunk (ctx , FLB_STORAGE_FS ,
532+ "in_tail" ,
533+ "restore-down-0-0000000000.000000000.flb" ,
534+ payload );
535+ TEST_CHECK (src != NULL );
536+
537+ if (cio_chunk_is_up (src ) == CIO_TRUE ) {
538+ TEST_CHECK (cio_chunk_down (src ) == CIO_OK );
539+ }
540+ TEST_CHECK (cio_chunk_is_up (src ) != CIO_TRUE );
541+
542+ rc = flb_storage_quarantine_chunk (ctx , src ,
543+ "tag.down" , 500 , "out_http" );
544+ TEST_CHECK (rc == 0 );
545+
546+ TEST_CHECK (cio_chunk_is_up (src ) != CIO_TRUE );
547+
548+ cio_chunk_close (src , CIO_FALSE );
549+ test_cleanup_with_cio (ctx , root );
550+ }
551+
552+ static void test_dlq_preserves_chunk_state_when_initially_up (void )
553+ {
554+ char root [256 ], rejdir [256 ];
555+ struct flb_config * ctx = NULL ;
556+ struct cio_chunk * src = NULL ;
557+ int rc ;
558+ const char * payload = "{\"msg\":\"state-preserve-up\"}\n" ;
559+
560+ tmpdir_for (root , sizeof (root ), "preserve-up" );
561+ snprintf (rejdir , sizeof (rejdir ), "%s/%s" , root , "rejected" );
562+ mkpath (rejdir );
563+
564+ ctx = make_ctx_fs (root , "rejected" );
565+
566+ src = make_src_chunk (ctx , FLB_STORAGE_FS ,
567+ "preserve_in" ,
568+ "preserve-up-0-0000000000.000000000.flb" ,
569+ payload );
570+ TEST_CHECK (src != NULL );
571+
572+ if (cio_chunk_is_up (src ) != CIO_TRUE ) {
573+ TEST_CHECK (cio_chunk_up_force (src ) == CIO_OK );
574+ }
575+ TEST_CHECK (cio_chunk_is_up (src ) == CIO_TRUE );
576+
577+ rc = flb_storage_quarantine_chunk (ctx , src ,
578+ "tag.up" , 502 , "out_es" );
579+ TEST_CHECK (rc == 0 );
580+
581+ TEST_CHECK (cio_chunk_is_up (src ) == CIO_TRUE );
582+
583+ cio_chunk_close (src , CIO_FALSE );
584+ test_cleanup_with_cio (ctx , root );
585+ }
586+
516587TEST_LIST = {
517588 { "dlq_copy_from_fs_chunk" , test_dlq_copy_from_fs_chunk },
518589 { "dlq_disabled_no_copy" , test_dlq_disabled_no_copy },
590+ { "dlq_restores_chunk_state_when_initially_down" , test_dlq_restores_chunk_state_when_initially_down },
591+ { "dlq_preserves_chunk_state_when_initially_up" , test_dlq_preserves_chunk_state_when_initially_up },
519592 { NULL , NULL }
520593};
0 commit comments