GithubHelp home page GithubHelp logo

gyro's Introduction

Gryo介绍

https://plugins.jetbrains.com/plugin/20795-gyro

11673191821_ pic

它是一个IDEA插件,安装之后,用Gyro Debug运行你的单测,第一次会正常启动Spring容器,第二次之后再次运行会复用之前启动过的Spring容器。 如果你安装了Jrebel热部署插件,Gyro自动使用其热部署能力。

51673192009_ pic 认准Gyro Debug的黄色小蜜蜂,无需你为此改动任何代码,用它来执行你的单测,你将开启一段美妙的体验。

视频演示: https://youtu.be/2Kl0yGgz5f0

原理

原理其实就一句话:想办法复用第一次启动的进程。

在同一个中运行@SpringBootTest,Spring本身是做了缓存的,下面是我们在Idea中Debug运行@SpringBootTest的原理(以Junit4举例):

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {Application.class})
public abstract class TestDemo {
  
  @Test 
  public void test() {
    System.out.println("test");
  }
}

运行Debug的时候,Idea会启动一个进程,这个进程中通过反射获取注解@RunWith对应的类,然后启动Spring容器。 Spring在启动的时候,在TestContextManager中缓存了ApplicationContext,所以只要进程没有结束,再次运行的时候,Spring会从cache中获取Spring容器,并不会重新启动。 如下图所示:

81673192253_ pic

这里问题在于Idea每次Debug执行完成之后,都会把进程结束掉,进程都结束了,Spring的TextContextManager中的cache当然也就回收掉了。 所以其实只要复用第一次启动的进程,就能复用Spring容器!

Gyro Debug启动流程: Gyro自己写了一个GyroDebugRunner,通过本地文件通信的方式,和第一次启动的进程通信,把运行的参数写到本地文件中,第一次启动的进程监听这个文件的变化,读取其中的信息来执行。 第一次启动的时候,执行的是GyroTestStarter类,这个类会在执行完JunitStarter之后,会用While循环block住,监听本地文件的变化。

21673191822_ pic

gyro's People

Contributors

hghhhh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.