@@ -1592,4 +1592,176 @@ mod tests {
15921592
15931593 assert_eq ! ( exporter. len( ) , 1 ) ;
15941594 }
1595+
1596+ #[ test]
1597+ #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
1598+ fn test_build_batch_log_processor_builder_rt ( ) {
1599+ let mut env_vars = vec ! [
1600+ ( OTEL_BLRP_MAX_EXPORT_BATCH_SIZE , Some ( "500" ) ) ,
1601+ ( OTEL_BLRP_SCHEDULE_DELAY , Some ( "I am not number" ) ) ,
1602+ ( OTEL_BLRP_EXPORT_TIMEOUT , Some ( "2046" ) ) ,
1603+ ] ;
1604+ temp_env:: with_vars ( env_vars. clone ( ) , || {
1605+ let builder = BatchLogProcessorWithAsyncRuntime :: builder (
1606+ InMemoryLogExporter :: default ( ) ,
1607+ runtime:: Tokio ,
1608+ ) ;
1609+
1610+ assert_eq ! ( builder. config. max_export_batch_size, 500 ) ;
1611+ assert_eq ! (
1612+ builder. config. scheduled_delay,
1613+ Duration :: from_millis( OTEL_BLRP_SCHEDULE_DELAY_DEFAULT )
1614+ ) ;
1615+ assert_eq ! (
1616+ builder. config. max_queue_size,
1617+ OTEL_BLRP_MAX_QUEUE_SIZE_DEFAULT
1618+ ) ;
1619+ assert_eq ! (
1620+ builder. config. max_export_timeout,
1621+ Duration :: from_millis( 2046 )
1622+ ) ;
1623+ } ) ;
1624+
1625+ env_vars. push ( ( OTEL_BLRP_MAX_QUEUE_SIZE , Some ( "120" ) ) ) ;
1626+
1627+ temp_env:: with_vars ( env_vars, || {
1628+ let builder = BatchLogProcessorWithAsyncRuntime :: builder (
1629+ InMemoryLogExporter :: default ( ) ,
1630+ runtime:: Tokio ,
1631+ ) ;
1632+ assert_eq ! ( builder. config. max_export_batch_size, 120 ) ;
1633+ assert_eq ! ( builder. config. max_queue_size, 120 ) ;
1634+ } ) ;
1635+ }
1636+
1637+ #[ test]
1638+ #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
1639+ fn test_build_batch_log_processor_builder_rt_with_custom_config ( ) {
1640+ let expected = BatchConfigBuilder :: default ( )
1641+ . with_max_export_batch_size ( 1 )
1642+ . with_scheduled_delay ( Duration :: from_millis ( 2 ) )
1643+ . with_max_export_timeout ( Duration :: from_millis ( 3 ) )
1644+ . with_max_queue_size ( 4 )
1645+ . build ( ) ;
1646+
1647+ let builder = BatchLogProcessorWithAsyncRuntime :: builder (
1648+ InMemoryLogExporter :: default ( ) ,
1649+ runtime:: Tokio ,
1650+ )
1651+ . with_batch_config ( expected) ;
1652+
1653+ let actual = & builder. config ;
1654+ assert_eq ! ( actual. max_export_batch_size, 1 ) ;
1655+ assert_eq ! ( actual. scheduled_delay, Duration :: from_millis( 2 ) ) ;
1656+ assert_eq ! ( actual. max_export_timeout, Duration :: from_millis( 3 ) ) ;
1657+ assert_eq ! ( actual. max_queue_size, 4 ) ;
1658+ }
1659+
1660+ #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
1661+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
1662+ async fn test_set_resource_batch_processor_rt ( ) {
1663+ let exporter = MockLogExporter {
1664+ resource : Arc :: new ( Mutex :: new ( None ) ) ,
1665+ } ;
1666+ let processor = BatchLogProcessorWithAsyncRuntime :: new (
1667+ Box :: new ( exporter. clone ( ) ) ,
1668+ BatchConfig :: default ( ) ,
1669+ runtime:: Tokio ,
1670+ ) ;
1671+ let provider = LoggerProvider :: builder ( )
1672+ . with_log_processor ( processor)
1673+ . with_resource ( Resource :: new ( vec ! [
1674+ KeyValue :: new( "k1" , "v1" ) ,
1675+ KeyValue :: new( "k2" , "v3" ) ,
1676+ KeyValue :: new( "k3" , "v3" ) ,
1677+ KeyValue :: new( "k4" , "v4" ) ,
1678+ KeyValue :: new( "k5" , "v5" ) ,
1679+ ] ) )
1680+ . build ( ) ;
1681+ tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ; // set resource in batch span processor is not blocking. Should we make it blocking?
1682+ assert_eq ! ( exporter. get_resource( ) . unwrap( ) . into_iter( ) . count( ) , 5 ) ;
1683+ let _ = provider. shutdown ( ) ;
1684+ }
1685+
1686+ #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
1687+ #[ tokio:: test( flavor = "multi_thread" ) ]
1688+ async fn test_batch_shutdown_rt ( ) {
1689+ // assert we will receive an error
1690+ // setup
1691+ let exporter = InMemoryLogExporterBuilder :: default ( )
1692+ . keep_records_on_shutdown ( )
1693+ . build ( ) ;
1694+ let processor = BatchLogProcessorWithAsyncRuntime :: new (
1695+ Box :: new ( exporter. clone ( ) ) ,
1696+ BatchConfig :: default ( ) ,
1697+ runtime:: Tokio ,
1698+ ) ;
1699+
1700+ let mut record = LogRecord :: default ( ) ;
1701+ let instrumentation = InstrumentationScope :: default ( ) ;
1702+
1703+ processor. emit ( & mut record, & instrumentation) ;
1704+ processor. force_flush ( ) . unwrap ( ) ;
1705+ processor. shutdown ( ) . unwrap ( ) ;
1706+ // todo: expect to see errors here. How should we assert this?
1707+ processor. emit ( & mut record, & instrumentation) ;
1708+ assert_eq ! ( 1 , exporter. get_emitted_logs( ) . unwrap( ) . len( ) )
1709+ }
1710+
1711+ #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
1712+ #[ tokio:: test( flavor = "current_thread" ) ]
1713+ #[ ignore = "See issue https://github.com/open-telemetry/opentelemetry-rust/issues/1968" ]
1714+ async fn test_batch_log_processor_rt_shutdown_with_async_runtime_current_flavor_multi_thread ( ) {
1715+ let exporter = InMemoryLogExporterBuilder :: default ( ) . build ( ) ;
1716+ let processor = BatchLogProcessorWithAsyncRuntime :: new (
1717+ Box :: new ( exporter. clone ( ) ) ,
1718+ BatchConfig :: default ( ) ,
1719+ runtime:: Tokio ,
1720+ ) ;
1721+
1722+ //
1723+ // deadloack happens in shutdown with tokio current_thread runtime
1724+ //
1725+ processor. shutdown ( ) . unwrap ( ) ;
1726+ }
1727+
1728+ #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
1729+ #[ tokio:: test( flavor = "current_thread" ) ]
1730+ async fn test_batch_log_processor_rt_shutdown_with_async_runtime_current_flavor_current_thread ( )
1731+ {
1732+ let exporter = InMemoryLogExporterBuilder :: default ( ) . build ( ) ;
1733+ let processor = BatchLogProcessorWithAsyncRuntime :: new (
1734+ Box :: new ( exporter. clone ( ) ) ,
1735+ BatchConfig :: default ( ) ,
1736+ runtime:: TokioCurrentThread ,
1737+ ) ;
1738+
1739+ processor. shutdown ( ) . unwrap ( ) ;
1740+ }
1741+
1742+ #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
1743+ #[ tokio:: test( flavor = "multi_thread" ) ]
1744+ async fn test_batch_log_processor_rt_shutdown_with_async_runtime_multi_flavor_multi_thread ( ) {
1745+ let exporter = InMemoryLogExporterBuilder :: default ( ) . build ( ) ;
1746+ let processor = BatchLogProcessorWithAsyncRuntime :: new (
1747+ Box :: new ( exporter. clone ( ) ) ,
1748+ BatchConfig :: default ( ) ,
1749+ runtime:: Tokio ,
1750+ ) ;
1751+
1752+ processor. shutdown ( ) . unwrap ( ) ;
1753+ }
1754+
1755+ #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
1756+ #[ tokio:: test( flavor = "multi_thread" ) ]
1757+ async fn test_batch_log_processor_rt_shutdown_with_async_runtime_multi_flavor_current_thread ( ) {
1758+ let exporter = InMemoryLogExporterBuilder :: default ( ) . build ( ) ;
1759+ let processor = BatchLogProcessorWithAsyncRuntime :: new (
1760+ Box :: new ( exporter. clone ( ) ) ,
1761+ BatchConfig :: default ( ) ,
1762+ runtime:: TokioCurrentThread ,
1763+ ) ;
1764+
1765+ processor. shutdown ( ) . unwrap ( ) ;
1766+ }
15951767}
0 commit comments