From a2194e580c4c6a0325a0531d8ef170f78dd6f415 Mon Sep 17 00:00:00 2001 From: philwo Date: Tue, 6 Jun 2017 05:12:51 -0400 Subject: Add an example that shows how to use the cpu: tag for tests. Also serves as an example for bug #3106. PiperOrigin-RevId: 158116940 --- .../src/test/java/com/example/myproject/BUILD | 34 ++++++++++++++++++++++ .../test/java/com/example/myproject/TestSleep.java | 12 ++++++++ 2 files changed, 46 insertions(+) create mode 100644 examples/java-native/src/test/java/com/example/myproject/TestSleep.java (limited to 'examples') diff --git a/examples/java-native/src/test/java/com/example/myproject/BUILD b/examples/java-native/src/test/java/com/example/myproject/BUILD index c804f9fe60..72066b3f0a 100644 --- a/examples/java-native/src/test/java/com/example/myproject/BUILD +++ b/examples/java-native/src/test/java/com/example/myproject/BUILD @@ -35,6 +35,40 @@ java_test( deps = ["//third_party:junit4"], ) +# This exercises the "cpu:" tag. +# +# Expected behavior: +# test0 and test1 run together then one of the other two alone, and then the remaining one alone. +java_test( + name = "sleep0", + srcs = ["TestSleep.java"], + test_class = "com.example.myproject.TestSleep", + deps = ["//third_party:junit4"], +) + +java_test( + name = "sleep1", + srcs = ["TestSleep.java"], + test_class = "com.example.myproject.TestSleep", + deps = ["//third_party:junit4"], +) + +java_test( + name = "sleep2", + srcs = ["TestSleep.java"], + tags = ["cpu:20000"], + test_class = "com.example.myproject.TestSleep", + deps = ["//third_party:junit4"], +) + +java_test( + name = "sleep3", + srcs = ["TestSleep.java"], + tags = ["cpu:20000"], + test_class = "com.example.myproject.TestSleep", + deps = ["//third_party:junit4"], +) + # This attempts to run TestCustomGreeting.java without any resources, so fails. java_test( name = "resource-fail", diff --git a/examples/java-native/src/test/java/com/example/myproject/TestSleep.java b/examples/java-native/src/test/java/com/example/myproject/TestSleep.java new file mode 100644 index 0000000000..21e2271bd1 --- /dev/null +++ b/examples/java-native/src/test/java/com/example/myproject/TestSleep.java @@ -0,0 +1,12 @@ +package com.example.myproject; + +import org.junit.Test; + +/** Contains a single test that just sleeps for 15 seconds and then succeeds. */ +public class TestSleep { + @Test + public void testSleep() throws Exception { + // Sleep for 15 seconds. + Thread.sleep(15 * 1000); + } +} -- cgit v1.2.3