@@ -539,4 +539,59 @@ public function testSetTimeoutAboveMaximum(): void
539539 $ adapter = new ClickHouseAdapter ($ host , $ username , $ password , $ port );
540540 $ adapter ->setTimeout (600001 ); // Above maximum
541541 }
542+
543+ /**
544+ * Test compression functionality
545+ */
546+ public function testCompression (): void
547+ {
548+ // Create a new adapter instance with compression enabled
549+ $ host = getenv ('CLICKHOUSE_HOST ' ) ?: 'clickhouse ' ;
550+ $ username = getenv ('CLICKHOUSE_USER ' ) ?: 'default ' ;
551+ $ password = getenv ('CLICKHOUSE_PASSWORD ' ) ?: 'clickhouse ' ;
552+ $ port = (int ) (getenv ('CLICKHOUSE_PORT ' ) ?: 8123 );
553+ $ secure = (bool ) (getenv ('CLICKHOUSE_SECURE ' ) ?: false );
554+
555+ $ adapter = new ClickHouseAdapter ($ host , $ username , $ password , $ port , $ secure );
556+ $ adapter ->setNamespace ('utopia_usage_compression_test ' );
557+ $ adapter ->setTenant (1 );
558+
559+ if ($ database = getenv ('CLICKHOUSE_DATABASE ' )) {
560+ $ adapter ->setDatabase ($ database );
561+ }
562+
563+ $ usage = new Usage ($ adapter );
564+ $ usage ->setup ();
565+
566+ // Test enabling compression
567+ $ result = $ adapter ->setCompression (true );
568+ $ this ->assertInstanceOf (ClickHouseAdapter::class, $ result );
569+
570+ // Test disabling compression
571+ $ result = $ adapter ->setCompression (false );
572+ $ this ->assertInstanceOf (ClickHouseAdapter::class, $ result );
573+
574+ // Enable compression for all subsequent operations
575+ $ adapter ->setCompression (true );
576+
577+ // Insert data using logBatch with compression enabled
578+ $ batchResult = $ usage ->logBatch ([
579+ ['metric ' => 'compression.test.batch ' , 'value ' => 50 , 'period ' => '1h ' , 'tags ' => ['type ' => 'batch ' ]],
580+ ['metric ' => 'compression.test.batch ' , 'value ' => 75 , 'period ' => '1h ' , 'tags ' => ['type ' => 'batch ' ]],
581+ ['metric ' => 'compression.test.single ' , 'value ' => 100 , 'period ' => '1h ' , 'tags ' => ['type ' => 'single ' ]],
582+ ]);
583+ $ this ->assertTrue ($ batchResult );
584+
585+ // Verify find query works with compression (returns array)
586+ $ metrics = $ usage ->find ([]);
587+ $ this ->assertIsArray ($ metrics );
588+
589+ // Verify count query works with compression (returns int)
590+ $ count = $ usage ->count ([]);
591+ $ this ->assertIsInt ($ count );
592+
593+ // Verify sum operation works with compression (returns int)
594+ $ sum = $ usage ->sumByPeriod ('compression.test.batch ' , '1h ' );
595+ $ this ->assertIsInt ($ sum );
596+ }
542597}
0 commit comments