|
27 | 27 | import com.google.cloud.bigquery.FieldValue.Attribute; |
28 | 28 | import com.google.cloud.bigquery.FieldValueList; |
29 | 29 | import com.google.cloud.bigquery.LegacySQLTypeName; |
| 30 | +import java.nio.file.Path; |
30 | 31 | import java.util.ArrayList; |
31 | 32 | import java.util.Collections; |
32 | 33 | import java.util.HashMap; |
|
41 | 42 | import org.junit.jupiter.api.AfterEach; |
42 | 43 | import org.junit.jupiter.api.BeforeEach; |
43 | 44 | import org.junit.jupiter.api.Test; |
| 45 | +import org.junit.jupiter.api.io.TempDir; |
44 | 46 |
|
45 | 47 | public class BigQueryJdbcCustomLoggerTest extends BigQueryJdbcLoggingBaseTest { |
46 | 48 |
|
@@ -118,6 +120,28 @@ public void testLazyCallerInference() { |
118 | 120 | assertEquals("testLazyCallerInference", methodName); |
119 | 121 | } |
120 | 122 |
|
| 123 | + @Test |
| 124 | + public void testCallerInferenceWithPerConnectionFileHandler(@TempDir Path tempDir) { |
| 125 | + PerConnectionFileHandler perConnHandler = |
| 126 | + new PerConnectionFileHandler(tempDir.toString(), Level.ALL); |
| 127 | + try { |
| 128 | + logger.fine("Message through PerConnectionFileHandler"); |
| 129 | + |
| 130 | + List<LogRecord> records = testHandler.getRecords(); |
| 131 | + assertEquals(1, records.size()); |
| 132 | + LogRecord record = records.get(0); |
| 133 | + |
| 134 | + // Publish record via PerConnectionFileHandler to put PerConnectionFileHandler on stack trace |
| 135 | + perConnHandler.publish(record); |
| 136 | + |
| 137 | + // Verify that caller inference skips PerConnectionFileHandler frame |
| 138 | + assertEquals(BigQueryJdbcCustomLoggerTest.class.getName(), record.getSourceClassName()); |
| 139 | + assertEquals("testCallerInferenceWithPerConnectionFileHandler", record.getSourceMethodName()); |
| 140 | + } finally { |
| 141 | + perConnHandler.close(); |
| 142 | + } |
| 143 | + } |
| 144 | + |
121 | 145 | @Test |
122 | 146 | public void testHotPathLoggerLogToDefaultWhenContextIsNull() { |
123 | 147 | BigQueryJdbcCustomLogger hotpathLogger = |
|
0 commit comments