简体   繁体   English

如何在不依赖于Pivotal GemFire缓存的情况下启动Spring Boot应用

[英]How to start Spring Boot app without depending on Pivotal GemFire cache

I have a Spring Boot app with a Pivotal GemFire ClientCache instance configured and its corresponding domain objects. 我有一个配置了Pivotal GemFire ClientCache实例及其对应域对象的Spring Boot应用程序。 I am also using Spring Boot Test for unit testing. 我还使用Spring Boot Test进行单元测试。 For every test case execution, either through class or Maven build, Spring ApplicationContext fails to load if the GemFire cache is down. 对于每个测试用例,无论是通过类还是通过Maven构建,如果GemFire缓存关闭,Spring ApplicationContext无法加载。

How to start Spring Boot application without depending on GemFire cache? 如何在不依赖GemFire缓存的情况下启动Spring Boot应用程序?

I am not sure I follow exactly what you mean by... 我不确定我是否完全按照您的意思...

" For every test case execution, either through class or Maven build, Spring ApplicationContext fails to load if the GemFire cache is down. " 对于每个测试用例执行,无论是通过类还是通过Maven构建,如果GemFire缓存关闭,Spring ApplicationContext无法加载。

Are you recreating the ClientCache instance for each test case (method) in your test class? 您是否正在为测试类中的每个测试用例(方法)重新创建ClientCache实例?

If so, then this can be tricky to do since even after calling ClientCache.close() , GemFire may not have completely "closed" and released all the resources used by the ClientCache instance. 如果是这样,那么这样做可能会很棘手,因为即使在调用ClientCache.close() ,GemFire可能还没有完全“关闭”并释放ClientCache实例使用的所有资源。 However, usually that does not prevent the Spring ApplicationContext from being recreated on subsequent test case executions. 但是,通常这并不妨碍在随后的测试用例执行时重新创建Spring ApplicationContext It usually just leads to subsequent test failures since the ClientCache instance is dirty, or stale, retaining old state from the previous (or last) test case execution. 由于ClientCache实例肮脏或陈旧,并保留了先前(或最后)测试案例执行的旧状态,因此通常只会导致后续测试失败。

Are you also using Spring's @DirtiesContext on your test case method as well? 您还在测试用例方法上使用Spring的@DirtiesContext吗?

Usually, it is wise to cycle the ApplicationContext and GemFire cache instance (eg ClientCache ) per test class, where each test case method in the test class will use the same ApplicationContext and ClientCache instance; 通常,明智的做法是每个测试类循环ApplicationContext和GemFire缓存实例(例如ClientCache ),其中测试类中的每个测试用例方法将使用相同的ApplicationContextClientCache实例; this is the most ideal. 这是最理想的。

With that, I have 2 things to share with you: 因此,我有两件事要与您分享:

  1. First, have a look at the new Spring Boot for Apache Geode/Pivotal GemFire project. 首先,看看用于Apache Geode / Pivotal GemFire项目的新Spring Boot Documentation is here . 文档在这里 I announced the availability of this project nearly a month ago now. 我近一个月前宣布了该项目的可用性。 This project takes a "client-side" perspective to building Spring Boot applications with Pivotal GemFire. 该项目从“客户端”的角度来使用Pivotal GemFire构建Spring Boot应用程序。 That is, it gives you an auto-configured ClientCache instance by default. 也就是说,默认情况下它为您提供了一个自动配置的ClientCache实例。

  2. Specifically, have a look at Spring Boot for Pivotal GemFire's test suite, beginning here . 具体来说,从此处开始, 查看 适用于Pivotal GemFire的测试套件的Spring Boot Nearly all these test classes use a ClientCache instance and test various aspects of Pivotal GemFire, such as CQ's or Security, etc. 几乎所有这些测试类都使用ClientCache实例并测试Pivotal GemFire的各个方面,例如CQ或Security等。

  3. In certain test classes, I used a "mock" ClientCache instance (for example, this test class , and this test configuration in particular). 在某些测试类中,我使用了“模拟” ClientCache实例(例如,该测试类 ,尤其是该测试配置 )。 However, in many other cases, I used a live GemFire ClientCache instance, for example or this test class , which is interesting since this test class even launches a server for the ClientCache instance (the test itself) to connect to. 然而,在许多其他情况下,我用了一个活的GemFire ClientCache例如,对于例如或者这个测试类 ,这是有趣,因为这个测试类,甚至启动一个服务器ClientCache实例(测试本身)来连接。

  4. All the test coordination logic in Spring Boot for Apache Geode/Pivotal GemFire is provided by another new project, Spring Test for Apache Geode/Pivotal GemFire . Spring Boot中用于Apache Geode / Pivotal GemFire的所有测试协调逻辑均由另一个新项目提供,即Apache Geode / Pivotal GemFire的Spring Test Unfortunately, Spring Test for Apache Geode/Pivotal GemFire is still largely a WIP, so does not have documentation yet. 不幸的是, Apache Geode / Pivotal GemFire的Spring Test在很大程度上仍是WIP,因此尚无文档。 However, I have used this new test project extensively to test Spring Boot for Apache Geode/Pivotal GemFire . 但是,我已经广泛使用了这个新的测试项目来为Apache Geode / Pivotal GemFire测试Spring Boot You will see its presence in the extension classes, like ForkingClientServerIntegrationTestsSupport , and so on. 您将在扩展类(例如ForkingClientServerIntegrationTestsSupport等)中看到它的存在。

In summary, use the new Spring Boot for Pivotal GemFire & Spring Test for Pivotal GemFire project as your guide for writing more effective Unit and Integration tests. 总之,将新的Pivotal GemFire的Spring Boot和Pivotal GemFire的 Spring Test项目用作编写更有效的单元和集成测试的指南。

Finally, if you have an example GitHub repository reproducing your problem, I can help point you in the right direction. 最后,如果您有一个示例GitHub存储库可以重现您的问题,那么我可以为您指明正确的方向。

Hope this helps! 希望这可以帮助!

Regards, John 问候,约翰

For your unit tests, use a different profile. 对于单元测试,请使用其他配置文件。 Say application-ut.yaml and ask spring not to use any cache implementation library: application-ut.yaml并要求spring不要使用任何缓存实现库:

application-ut.yaml (add below entry and remove whatever implementation u configured for Gemfire) application-ut.yaml (在条目下方添加并删除您为Gemfire配置的所有实现)

spring.cache.type : simple

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重要的GemFire 9.3.0:GemFire集群中的Spring Data GemFire XML配置 - Pivotal GemFire 9.3.0: Spring Data GemFire XML config in GemFire cluster Pivotal GemFire多会话的春季会议 - Spring Session for Pivotal GemFire Multi-Session Pivotal GemFire:Spring Data GemFire中的PDX序列化器配置 - Pivotal GemFire: PDX serializer config in Spring Data GemFire 在不依赖数据库 oracle 的用户名和密码的情况下启动 spring-boot 应用程序? - Start spring-boot app without depending on username and password for Database oracle? 通过从Spring Boot应用程序加载数据映射来初始化GemFire缓存 - Initialize a GemFire cache by loading a Map of data from Spring Boot application 如何定义本地枢纽GemFire区域的持久性? - How to define persistence on Local Pivotal GemFire Region? Spring Boot先失败,然后在Pivotal Cloud Foundry中自动启动 - Spring boot rashes first and then start automatically in Pivotal Cloud Foundry 如何在 Spring Integration DSL 中将对象放入 Gemfire Cache? - How to put object to Gemfire Cache in Spring Integration DSL? 关键的gemfire负载测试 - Pivotal gemfire load testing 尝试使用 Spring Boot 2 启动 gemfire 脉冲时出现 jackson cast 异常 - Getting jackson cast exception while trying to start gemfire pulse with spring boot 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM