@@ -154,7 +154,7 @@ public com.google.api.MonitoredResourceDescriptor apply(
154
154
private static final String NEXT_CURSOR = "nextCursor" ;
155
155
private static final Boolean DISABLED = Boolean .FALSE ;
156
156
private static final Timestamp EXCLUSION_CREATED_TIME = fromMillis (System .currentTimeMillis ());
157
- private static final Timestamp EXCLUSION_UPDATED_TIME = fromMillis (System .currentTimeMillis ());;
157
+ private static final Timestamp EXCLUSION_UPDATED_TIME = fromMillis (System .currentTimeMillis ());
158
158
private static final Exclusion EXCLUSION =
159
159
Exclusion .newBuilder (EXCLUSION_NAME , EXCLUSION_FILTER )
160
160
.setDisabled (DISABLED )
@@ -185,6 +185,18 @@ public void setUp() {
185
185
.setServiceRpcFactory (rpcFactoryMock )
186
186
.setRetrySettings (ServiceOptions .getNoRetrySettings ())
187
187
.build ();
188
+
189
+ // By default when calling ListLogEntries, we append a filter of last 24 hours.
190
+ // However when testing, the time when it was called by the test and by the method
191
+ // implementation might differ by microseconds so we use the same time filter implementation
192
+ // for test and in "real" method
193
+ LoggingImpl .defaultTimestampFilterCreator =
194
+ new ITimestampDefaultFilter () {
195
+ @ Override
196
+ public String createDefaultTimestampFilter () {
197
+ return "timestamp>=\" 2020-10-30T15:39:09Z\" " ;
198
+ }
199
+ };
188
200
}
189
201
190
202
@ After
@@ -1585,7 +1597,7 @@ public void testDeleteLog_Null() {
1585
1597
}
1586
1598
1587
1599
@ Test
1588
- public void testDeleteLogAync () throws ExecutionException , InterruptedException {
1600
+ public void testDeleteLogAsync () throws ExecutionException , InterruptedException {
1589
1601
DeleteLogRequest request = DeleteLogRequest .newBuilder ().setLogName (LOG_NAME_PB ).build ();
1590
1602
ApiFuture <Empty > response = ApiFutures .immediateFuture (Empty .getDefaultInstance ());
1591
1603
EasyMock .expect (loggingRpcMock .delete (request )).andReturn (response );
@@ -1621,7 +1633,7 @@ public void testWriteLogEntries() {
1621
1633
}
1622
1634
1623
1635
@ Test
1624
- public void testWriteLogEntriesDoesnotEnableFlushByDefault () {
1636
+ public void testWriteLogEntriesDoesNotEnableFlushByDefault () {
1625
1637
WriteLogEntriesRequest request =
1626
1638
WriteLogEntriesRequest .newBuilder ()
1627
1639
.addAllEntries (
@@ -1679,7 +1691,7 @@ public void testWriteLogEntriesWithOptions() {
1679
1691
}
1680
1692
1681
1693
@ Test
1682
- public void testWriteLogEntriesAsync () throws ExecutionException , InterruptedException {
1694
+ public void testWriteLogEntriesAsync () {
1683
1695
WriteLogEntriesRequest request =
1684
1696
WriteLogEntriesRequest .newBuilder ()
1685
1697
.addAllEntries (
@@ -1723,16 +1735,16 @@ public void testListLogEntries() {
1723
1735
String cursor = "cursor" ;
1724
1736
EasyMock .replay (rpcFactoryMock );
1725
1737
logging = options .getService ();
1726
- ListLogEntriesRequest request =
1727
- ListLogEntriesRequest .newBuilder ().addResourceNames (PROJECT_PB ).build ();
1738
+
1728
1739
List <LogEntry > entriesList = ImmutableList .of (LOG_ENTRY1 , LOG_ENTRY2 );
1729
1740
ListLogEntriesResponse response =
1730
1741
ListLogEntriesResponse .newBuilder ()
1731
1742
.setNextPageToken (cursor )
1732
1743
.addAllEntries (Lists .transform (entriesList , LogEntry .toPbFunction (PROJECT )))
1733
1744
.build ();
1734
1745
ApiFuture <ListLogEntriesResponse > futureResponse = ApiFutures .immediateFuture (response );
1735
- EasyMock .expect (loggingRpcMock .list (request )).andReturn (futureResponse );
1746
+ EasyMock .expect (loggingRpcMock .list (EasyMock .anyObject (ListLogEntriesRequest .class )))
1747
+ .andReturn (futureResponse );
1736
1748
EasyMock .replay (loggingRpcMock );
1737
1749
Page <LogEntry > page = logging .listLogEntries ();
1738
1750
assertEquals (cursor , page .getNextPageToken ());
@@ -1744,11 +1756,18 @@ public void testListLogEntriesNextPage() throws ExecutionException, InterruptedE
1744
1756
String cursor1 = "cursor" ;
1745
1757
EasyMock .replay (rpcFactoryMock );
1746
1758
logging = options .getService ();
1759
+
1760
+ String defaultTimeFilter =
1761
+ LoggingImpl .defaultTimestampFilterCreator .createDefaultTimestampFilter ();
1747
1762
ListLogEntriesRequest request1 =
1748
- ListLogEntriesRequest .newBuilder ().addResourceNames (PROJECT_PB ).build ();
1763
+ ListLogEntriesRequest .newBuilder ()
1764
+ .addResourceNames (PROJECT_PB )
1765
+ .setFilter (defaultTimeFilter )
1766
+ .build ();
1749
1767
ListLogEntriesRequest request2 =
1750
1768
ListLogEntriesRequest .newBuilder ()
1751
1769
.addResourceNames (PROJECT_PB )
1770
+ .setFilter (defaultTimeFilter )
1752
1771
.setPageToken (cursor1 )
1753
1772
.build ();
1754
1773
List <LogEntry > descriptorList1 = ImmutableList .of (LOG_ENTRY1 , LOG_ENTRY2 );
@@ -1785,7 +1804,11 @@ public void testListLogEntriesEmpty() {
1785
1804
EasyMock .replay (rpcFactoryMock );
1786
1805
logging = options .getService ();
1787
1806
ListLogEntriesRequest request =
1788
- ListLogEntriesRequest .newBuilder ().addResourceNames (PROJECT_PB ).build ();
1807
+ ListLogEntriesRequest .newBuilder ()
1808
+ .addResourceNames (PROJECT_PB )
1809
+ .setFilter (LoggingImpl .defaultTimestampFilterCreator .createDefaultTimestampFilter ())
1810
+ .build ();
1811
+
1789
1812
List <LogEntry > entriesList = ImmutableList .of ();
1790
1813
ListLogEntriesResponse response =
1791
1814
ListLogEntriesResponse .newBuilder ()
@@ -1809,7 +1832,10 @@ public void testListLogEntriesWithOptions() {
1809
1832
ListLogEntriesRequest .newBuilder ()
1810
1833
.addResourceNames (PROJECT_PB )
1811
1834
.setOrderBy ("timestamp desc" )
1812
- .setFilter ("logName:syslog" )
1835
+ .setFilter (
1836
+ String .format (
1837
+ "logName:syslog AND %s" ,
1838
+ LoggingImpl .defaultTimestampFilterCreator .createDefaultTimestampFilter ()))
1813
1839
.build ();
1814
1840
List <LogEntry > entriesList = ImmutableList .of (LOG_ENTRY1 , LOG_ENTRY2 );
1815
1841
ListLogEntriesResponse response =
@@ -1834,7 +1860,10 @@ public void testListLogEntriesAsync() throws ExecutionException, InterruptedExce
1834
1860
EasyMock .replay (rpcFactoryMock );
1835
1861
logging = options .getService ();
1836
1862
ListLogEntriesRequest request =
1837
- ListLogEntriesRequest .newBuilder ().addResourceNames (PROJECT_PB ).build ();
1863
+ ListLogEntriesRequest .newBuilder ()
1864
+ .addResourceNames (PROJECT_PB )
1865
+ .setFilter (LoggingImpl .defaultTimestampFilterCreator .createDefaultTimestampFilter ())
1866
+ .build ();
1838
1867
List <LogEntry > entriesList = ImmutableList .of (LOG_ENTRY1 , LOG_ENTRY2 );
1839
1868
ListLogEntriesResponse response =
1840
1869
ListLogEntriesResponse .newBuilder ()
@@ -1855,10 +1884,14 @@ public void testListLogEntriesAsyncNextPage() {
1855
1884
EasyMock .replay (rpcFactoryMock );
1856
1885
logging = options .getService ();
1857
1886
ListLogEntriesRequest request1 =
1858
- ListLogEntriesRequest .newBuilder ().addResourceNames (PROJECT_PB ).build ();
1887
+ ListLogEntriesRequest .newBuilder ()
1888
+ .addResourceNames (PROJECT_PB )
1889
+ .setFilter (LoggingImpl .defaultTimestampFilterCreator .createDefaultTimestampFilter ())
1890
+ .build ();
1859
1891
ListLogEntriesRequest request2 =
1860
1892
ListLogEntriesRequest .newBuilder ()
1861
1893
.addResourceNames (PROJECT_PB )
1894
+ .setFilter (LoggingImpl .defaultTimestampFilterCreator .createDefaultTimestampFilter ())
1862
1895
.setPageToken (cursor1 )
1863
1896
.build ();
1864
1897
List <LogEntry > descriptorList1 = ImmutableList .of (LOG_ENTRY1 , LOG_ENTRY2 );
@@ -1890,12 +1923,15 @@ public void testListLogEntriesAsyncNextPage() {
1890
1923
}
1891
1924
1892
1925
@ Test
1893
- public void testListLogEntriesAyncEmpty () throws ExecutionException , InterruptedException {
1926
+ public void testListLogEntriesAsyncEmpty () throws ExecutionException , InterruptedException {
1894
1927
String cursor = "cursor" ;
1895
1928
EasyMock .replay (rpcFactoryMock );
1896
1929
logging = options .getService ();
1897
1930
ListLogEntriesRequest request =
1898
- ListLogEntriesRequest .newBuilder ().addResourceNames (PROJECT_PB ).build ();
1931
+ ListLogEntriesRequest .newBuilder ()
1932
+ .addResourceNames (PROJECT_PB )
1933
+ .setFilter (LoggingImpl .defaultTimestampFilterCreator .createDefaultTimestampFilter ())
1934
+ .build ();
1899
1935
List <LogEntry > entriesList = ImmutableList .of ();
1900
1936
ListLogEntriesResponse response =
1901
1937
ListLogEntriesResponse .newBuilder ()
@@ -1915,11 +1951,15 @@ public void testListLogEntriesAsyncWithOptions() throws ExecutionException, Inte
1915
1951
String cursor = "cursor" ;
1916
1952
EasyMock .replay (rpcFactoryMock );
1917
1953
logging = options .getService ();
1954
+ String filter =
1955
+ String .format (
1956
+ "logName:syslog AND %s" ,
1957
+ LoggingImpl .defaultTimestampFilterCreator .createDefaultTimestampFilter ());
1918
1958
ListLogEntriesRequest request =
1919
1959
ListLogEntriesRequest .newBuilder ()
1920
1960
.addResourceNames (PROJECT_PB )
1921
1961
.setOrderBy ("timestamp desc" )
1922
- .setFilter ("logName:syslog" )
1962
+ .setFilter (filter )
1923
1963
.build ();
1924
1964
List <LogEntry > entriesList = ImmutableList .of (LOG_ENTRY1 , LOG_ENTRY2 );
1925
1965
ListLogEntriesResponse response =
@@ -1933,7 +1973,7 @@ public void testListLogEntriesAsyncWithOptions() throws ExecutionException, Inte
1933
1973
AsyncPage <LogEntry > page =
1934
1974
logging
1935
1975
.listLogEntriesAsync (
1936
- EntryListOption .filter ("logName:syslog" ),
1976
+ EntryListOption .filter (filter ),
1937
1977
EntryListOption .sortOrder (SortingField .TIMESTAMP , Logging .SortingOrder .DESCENDING ))
1938
1978
.get ();
1939
1979
assertEquals (cursor , page .getNextPageToken ());
@@ -2011,8 +2051,8 @@ public void run() {
2011
2051
};
2012
2052
threads [i ].start ();
2013
2053
}
2014
- for (int i = 0 ; i < threads . length ; i ++ ) {
2015
- threads [ i ] .join ();
2054
+ for (Thread thread : threads ) {
2055
+ thread .join ();
2016
2056
}
2017
2057
assertSame (0 , exceptions .get ());
2018
2058
}
0 commit comments