{"id":17031451,"url":"https://github.com/platan/varnish-exec","last_synced_at":"2026-04-20T05:05:41.137Z","repository":{"id":25991294,"uuid":"29433580","full_name":"platan/varnish-exec","owner":"platan","description":"Java library, JUnit rule and Spring integration for running Varnish Cache daemon. ","archived":false,"fork":false,"pushed_at":"2016-12-18T20:33:25.000Z","size":127,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-28T00:42:11.966Z","etag":null,"topics":["java","junit","spring","varnish"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/platan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-18T17:12:42.000Z","updated_at":"2016-11-17T20:17:10.000Z","dependencies_parsed_at":"2022-08-24T14:19:24.143Z","dependency_job_id":null,"html_url":"https://github.com/platan/varnish-exec","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platan%2Fvarnish-exec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platan%2Fvarnish-exec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platan%2Fvarnish-exec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platan%2Fvarnish-exec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/platan","download_url":"https://codeload.github.com/platan/varnish-exec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245020314,"owners_count":20548156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","junit","spring","varnish"],"created_at":"2024-10-14T08:24:16.568Z","updated_at":"2026-04-20T05:05:41.112Z","avatar_url":"https://github.com/platan.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Varnish Exec [![Build Status](https://travis-ci.org/platan/varnish-exec.svg?branch=master)](https://travis-ci.org/platan/varnish-exec) [![Coverage Status](https://coveralls.io/repos/platan/varnish-exec/badge.svg?branch=master)](https://coveralls.io/r/platan/varnish-exec?branch=master) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.platan/varnish-exec-core/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.github.platan/varnish-exec-core)\nJava library and [JUnit](http://junit.org/) [rule](https://github.com/junit-team/junit/wiki/Rules) for running [Varnish Cache](https://www.varnish-cache.org/) daemon.\n\n- [Modules](#modules)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Examples](#examples)\n- [Customization](#customization)\n- [Changelog](#changelog)\n- [License](#license)\n\n## Modules\n- varnish-exec-core - Core module\n- varnish-exec-junit - Integration with the JUnit\n- varnish-exec-spring - Integration with the Spring TestContext Framework\n\n## Requirements\n- JDK 8\n- Varnish Cache 3.0, 4.0 or 5.0\n\n## Installation\n\nVarnish Exec is available in Maven Central.\n\nApache Maven:\n```xml\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.github.platan\u003c/groupId\u003e\n        \u003cartifactId\u003evarnish-exec-(core|junit|spring)\u003c/artifactId\u003e\n        \u003cversion\u003e0.2.1\u003c/version\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\nGradle:\n```gradle\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    testCompile 'com.github.platan:varnish-exec-(core|junit|spring):0.2.1'\n}\n```\n\nIn order to install it in your local Maven repository run:\n```shell\n./gradlew install\n```\n\n## Usage\nJUnit test using rule:\n```java\nimport com.github.platan.varnishexec.VarnishCommand;\nimport com.github.platan.varnishexec.junit.VarnishResource;\n\nimport org.junit.ClassRule;\n...\n\npublic class MyTest {\n\n    private static final VarnishCommand VARNISH_COMMAND = VarnishCommand.newBuilder()\n        .withConfigFile(\"./src/test/etc/varnish/default.vcl\").build();\n\n    @ClassRule\n    public static VarnishResource varnishResource = VarnishResource.build(VARNISH_COMMAND);\n\n    @Test\n    public void testSomethingWithRunningVarnish() throws Exception {\n        int port = varnishResource.getPort();\n        ...\n    }\n}\n```\nIn the above example we use a [ClassRule](https://github.com/junit-team/junit/wiki/Rules#classrule). Varnish Cache daemon starts once before all tests run and shutdowns after they are finished.\n\nAnother example using core varnish-exec API:\n```java\nimport org.junit.AfterClass;\nimport org.junit.BeforeClass;\n\nimport com.github.platan.varnishexec.VarnishCommand;\nimport com.github.platan.varnishexec.VarnishExecs;\nimport com.github.platan.varnishexec.VarnishProcess;\n...\n\npublic class MyTest {\n\n    private static VarnishProcess varnishProcess;\n\n    @BeforeClass\n    public static void setUpClass() {\n        VarnishCommand varnishCommand = VarnishCommand.newBuilder()\n                .withConfigFile(\"./src/test/etc/varnish/default.vcl\").build();\n        varnishProcess = VarnishExecs.start(varnishCommand);\n    }\n\n    @AfterClass\n    public static void tearDownClass() {\n        varnishProcess.kill();\n    }\n\n    @Test\n    public void testSomethingWithRunningVarnish() throws Exception {\n        int port = varnishProcess.getPort();\n        ...\n    }\n}\n```\n\nAn example using the `VarnishTest` annotation integrating varnish-exec with the Spring TestContext Framework:\n```java\nimport com.github.platan.varnishexec.spring.VarnishTest;\n\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\n\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.boot.test.context.SpringBootTest;\nimport org.springframework.test.context.junit4.SpringRunner;\n\n@RunWith(SpringRunner.class)\n@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)\n@VarnishTest(configFile = \"./src/test/etc/varnish/default.vcl\")\npublic class MyTest {\n\n    @Value(\"${local.varnish.port}\")\n    private String varnishPort;\n\n    @Test\n    public void testSomethingWithRunningVarnish() {\n        ...\n    }\n}\n```\nThe above examples will start a new process with default values:\n```shell\nvarnishd -a localhost:10080 -F -f ./src/test/etc/varnish/default.vcl -n /tmp\n```\n\n## Examples\nExamples can be found on [varnish-exec-example](https://github.com/platan/varnish-exec-example). \n\n## Customization\nUse `VarnishCommand` to override default arguments. Varnish daemon command can be configured by `varnishdCommand` parameter.\n\nAll supported `varnishd` options:\n\noption                       | varnishd parameter | parameter         | default value\n-----------------------------|--------------------|-------------------|------------------------------------\nlistening address            | -a                 | address           | localhost:10080\nbackend server               | -b                 | backend           |\nVCL configuration file       | -f                 | configFile        |\nmanagement interface address | -T                 | managementAddress |\ninstance name                | -n                 | name              | /tmp\nstorage backend              | -s                 | storage           |\n\nBuild a command:\n```java\nVarnishCommand command = VarnishCommand.newBuilder()\n                .withAddress(\"localhost\", 80)\n                .withConfigFile(\"service.vcl\")\n                .withManagementAddress(\"localhost\", 10000)\n                .withName(\"service\")\n                .withStorage(\"malloc,1G\")\n                .withVarnishdCommand(\"/usr/sbin/varnishd\").build();\n```\nThen pass it to `VarnishResource`:\n```java\nVarnishResource varnishResource = VarnishResource.build(command);\n```\nOr to `VarnishExecs#start`:\n```java\nVarnishProcess varnishProcess = VarnishExecs.start(command);\n```\n\n#### Spring\nThe `VarnishTest` class allows to define all options listed above. Furthermore, this class: \n- can set a random name and a random port\n- replaces `@local.port@` with a value of an application port (`local.server.port`) in a copy of VCL configuration file\n- sets `local.varnish.port` property with a value of a varnish port\n\nCheck a [documentation](https://github.com/platan/varnish-exec/blob/master/varnish-exec-spring/src/main/java/com/github/platan/varnishexec/spring/VarnishTest.java) for more information. \n\n## Changelog\n\n### 0.2.1 (2016-12-16)\n- a random port is selected from the range 1024 - 65535\n\n### 0.2.0 (2016-09-03)\n- (new feature) added varnish-exec-spring module providing integration with the Spring TestContext Framework\n\n### 0.1.0 (2015-01-25)\n- Initial release\n\n## License\nThis project is licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplatan%2Fvarnish-exec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplatan%2Fvarnish-exec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplatan%2Fvarnish-exec/lists"}