HttpSmokeTestCase.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Licensed to Elasticsearch under one or more contributor
  3. * license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright
  5. * ownership. Elasticsearch licenses this file to you under
  6. * the Apache License, Version 2.0 (the "License"); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.elasticsearch.http;
  20. import org.elasticsearch.common.network.NetworkModule;
  21. import org.elasticsearch.common.settings.Settings;
  22. import org.elasticsearch.plugins.Plugin;
  23. import org.elasticsearch.test.ESIntegTestCase;
  24. import org.elasticsearch.transport.Netty4Plugin;
  25. import org.elasticsearch.transport.nio.MockNioTransportPlugin;
  26. import org.elasticsearch.transport.nio.NioTransportPlugin;
  27. import org.junit.BeforeClass;
  28. import java.util.Arrays;
  29. import java.util.Collection;
  30. public abstract class HttpSmokeTestCase extends ESIntegTestCase {
  31. private static String nodeTransportTypeKey;
  32. private static String nodeHttpTypeKey;
  33. private static String clientTypeKey;
  34. @SuppressWarnings("unchecked")
  35. @BeforeClass
  36. public static void setUpTransport() {
  37. nodeTransportTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class));
  38. nodeHttpTypeKey = getHttpTypeKey(randomFrom(Netty4Plugin.class, NioTransportPlugin.class));
  39. clientTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class));
  40. }
  41. private static String getTypeKey(Class<? extends Plugin> clazz) {
  42. if (clazz.equals(MockNioTransportPlugin.class)) {
  43. return MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME;
  44. } else if (clazz.equals(NioTransportPlugin.class)) {
  45. return NioTransportPlugin.NIO_TRANSPORT_NAME;
  46. } else {
  47. assert clazz.equals(Netty4Plugin.class);
  48. return Netty4Plugin.NETTY_TRANSPORT_NAME;
  49. }
  50. }
  51. private static String getHttpTypeKey(Class<? extends Plugin> clazz) {
  52. if (clazz.equals(NioTransportPlugin.class)) {
  53. return NioTransportPlugin.NIO_HTTP_TRANSPORT_NAME;
  54. } else {
  55. assert clazz.equals(Netty4Plugin.class);
  56. return Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME;
  57. }
  58. }
  59. @Override
  60. protected boolean addMockHttpTransport() {
  61. return false; // enable http
  62. }
  63. @Override
  64. protected Settings nodeSettings(int nodeOrdinal) {
  65. return Settings.builder()
  66. .put(super.nodeSettings(nodeOrdinal))
  67. .put(NetworkModule.TRANSPORT_TYPE_KEY, nodeTransportTypeKey)
  68. .put(NetworkModule.HTTP_TYPE_KEY, nodeHttpTypeKey).build();
  69. }
  70. @Override
  71. protected Collection<Class<? extends Plugin>> nodePlugins() {
  72. return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class);
  73. }
  74. @Override
  75. protected Collection<Class<? extends Plugin>> transportClientPlugins() {
  76. return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class);
  77. }
  78. @Override
  79. protected Settings transportClientSettings() {
  80. return Settings.builder()
  81. .put(super.transportClientSettings())
  82. .put(NetworkModule.TRANSPORT_TYPE_KEY, clientTypeKey)
  83. .build();
  84. }
  85. @Override
  86. protected boolean ignoreExternalCluster() {
  87. return true;
  88. }
  89. }