我需要在应用程序层上实现超时。我将发送令牌,接收方将其重新发送给我。如果超过超时时间,我将引发异常并尝试重新连接到接收器。
问题是我无法使用阻止操作来读取流,因为我需要检查计时器的超时时间。
我尝试使用Scanner,DataInputStream和InputStream,但是它们的所有操作(nextDouble(),hasNext(),readDouble())都被阻止。
我认为唯一可行的方法是使用DataInputStream的可用方法,该方法是非阻塞的,但是它也不起作用。
15:36:13,740 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/Users/797/git/-Blocking-Service/app/target/test-classes/logback-test.xml]
15:36:13,849 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
15:36:13,850 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:36:13,864 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
15:36:13,942 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
15:36:13,942 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
15:36:13,942 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details
15:36:13,943 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
15:36:13,943 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
15:36:13,945 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.] to DEBUG
15:36:13,945 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.] to false
15:36:13,945 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[com.]
15:36:13,946 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to INFO
15:36:13,946 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.springframework] to false
15:36:13,946 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[org.springframework]
15:36:13,946 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.cxf] to INFO
15:36:13,946 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.apache.cxf] to false
15:36:13,946 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[org.apache.cxf]
15:36:13,946 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.security] to DEBUG
15:36:13,946 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.springframework.security] to false
15:36:13,946 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[org.springframework.security]
15:36:13,946 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:36:13,947 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@9573b3b - Registering current configuration as safe fallback point
2019-07-09 15:36:14 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
2019-07-09 15:36:14 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@1886991b, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@64aad809, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@1f03fba0, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@17dd671f, org.springframework.test.context.support.DirtiesContextTestExecutionListener@3bbf6abe, org.springframework.test.context.transaction.TransactionalTestExecutionListener@9679750, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@9b9a327, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@75a0c890, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@358ab600, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@e26af6, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@44065156, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@3791f50e]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.4 sec
Running com.....SwaggerConfigTest
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@347a171e, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@721b38e0, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@265edc64, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@78038d3e, org.springframework.test.context.support.DirtiesContextTestExecutionListener@1ca5b7c7, org.springframework.test.context.transaction.TransactionalTestExecutionListener@3752408b, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@673f17f9, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@3b10c5d, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@321b8863, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@1768c0b3, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@8779d78, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@3afbbcf]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.145 sec
Running com.....ServiceConfigurationTest
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@49172e03, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1cc1ddad, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@16869348, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@28b0eae9, org.springframework.test.context.support.DirtiesContextTestExecutionListener@58a7aeca, org.springframework.test.context.transaction.TransactionalTestExecutionListener@4a192cc6, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@68a7ea1e, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@476fb241, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@225b8598, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@21a7e209, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@76871b39, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@4cc05212]
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.16 sec
Running com.....dao.VoiceBlockingDAOImplTest
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@3d9033b, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@bfa9d56, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@4186a8f3, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@7fbe3398, org.springframework.test.context.support.DirtiesContextTestExecutionListener@34b5278f, org.springframework.test.context.transaction.TransactionalTestExecutionListener@6bfa0c62, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@1f4fe0de, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@11e3225c, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@c77f6b0, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@37d57240, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@577c2d74, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@5f850405]
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.049 sec
Running com....blocking.ApplicationTest
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com....blocking.ApplicationTest], using DelegatingSmartContextLoader
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.AbstractContextLoader - Could not detect default resource locations for test class [com....blocking.ApplicationTest]: no resource found for suffixes {-context.xml}.
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com....blocking.ApplicationTest]: ApplicationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
2019-07-09 15:36:16 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@55343a34, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@133420f8, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@560e6cbe, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5574f42b, org.springframework.test.context.support.DirtiesContextTestExecutionListener@21e5812b, org.springframework.test.context.transaction.TransactionalTestExecutionListener@1364560f, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@36aab341, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@448dcc13, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@496ce170, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@7809027c, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@1b5a8687, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@311d3cab]
2019-07-09 15:36:16 [main] DEBUG o.s.b.c.l.ClasspathLoggingApplicationListener - Application started with classpath: [file:/Users/797/git/-Blocking-Service/app/target/surefire/surefirebooter6895232110858784303.jar, file:/Users/797/git/-Blocking-Service/app/org/jacoco/org.jacoco.agent/0.8.3/org.jacoco.agent-0.8.3-runtime.jar]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.3.RELEASE)
2019-07-09 15:36:16 [main] INFO c.c...blocking.Application - Starting Application on COSML-1687603 with PID 26986 (started by 797 in /Users/797/git/-Blocking-Service/app)
2019-07-09 15:36:16 [main] DEBUG c.c...blocking.Application - Running with Spring Boot v2.1.3.RELEASE, Spring v5.1.5.RELEASE
谢谢大家