Skip to content

Commit af13f62

Browse files
stalarmichaelbausor
authored andcommitted
---
yaml --- r: 8157 b: refs/heads/tswast-patch-1 c: 797d665 h: refs/heads/master i: 8155: 08b838f
1 parent b1ea726 commit af13f62

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 2a922078f60e5e6c70d14a556b600f93d8b05b77
60+
refs/heads/tswast-patch-1: 797d665b84c9a518629a150365d98b846668a548
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,9 @@ public void onFailure(Throwable t) {
580580
}
581581
}
582582
});
583-
pendingWrites.add(writeFuture);
583+
synchronized (writeLock) {
584+
pendingWrites.add(writeFuture);
585+
}
584586
break;
585587
}
586588
}

branches/tswast-patch-1/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import java.util.List;
7171
import java.util.Map;
7272
import java.util.concurrent.ExecutionException;
73+
import java.util.concurrent.atomic.AtomicInteger;
7374
import org.easymock.EasyMock;
7475
import org.junit.After;
7576
import org.junit.Before;
@@ -1448,5 +1449,43 @@ public void run() {
14481449
flushWaiter.join(1000);
14491450
assertFalse(flushWaiter.isAlive());
14501451
}
1452+
1453+
@Test
1454+
public void testFlushStress() throws InterruptedException {
1455+
SettableApiFuture<WriteLogEntriesResponse> mockRpcResponse = SettableApiFuture.create();
1456+
mockRpcResponse.set(null);
1457+
replay(rpcFactoryMock);
1458+
logging = options.getService();
1459+
WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder()
1460+
.addAllEntries(Iterables.transform(ImmutableList.of(LOG_ENTRY1),
1461+
LogEntry.toPbFunction(PROJECT)))
1462+
.build();
1463+
1464+
Thread[] threads = new Thread[100];
1465+
EasyMock.expect(loggingRpcMock.write(request)).andReturn(mockRpcResponse).times(threads.length);
1466+
EasyMock.replay(loggingRpcMock);
1467+
1468+
// log and flush concurrently in many threads to trigger a ConcurrentModificationException
1469+
final AtomicInteger exceptions = new AtomicInteger(0);
1470+
for (int i = 0; i < threads.length; i++) {
1471+
threads[i] = new Thread() {
1472+
@Override
1473+
public void run() {
1474+
try {
1475+
logging.write(ImmutableList.of(LOG_ENTRY1));
1476+
logging.flush();
1477+
} catch (Exception ex) {
1478+
exceptions.incrementAndGet();
1479+
}
1480+
}
1481+
};
1482+
threads[i].start();
1483+
}
1484+
for (int i = 0; i < threads.length; i++) {
1485+
threads[i].join();
1486+
}
1487+
assertSame(0, exceptions.get());
1488+
}
1489+
14511490
}
14521491

0 commit comments

Comments
 (0)