• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HotelsDotCom / waggle-dance / #318

pending completion
#318

push

web-flow
Feature/upgrade springboot (#268)

* update springboot to 2.1.18

* update springboot to 2.2.13

* Upgrade to srping boot 2.7.11

* Update changelog

* Update changelog

* fix version

3 of 3 new or added lines in 2 files covered. (100.0%)

132 of 3058 relevant lines covered (4.32%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/waggle-dance-integration-tests/src/main/java/com/hotels/bdp/waggledance/junit/ServerSocketRule.java
1
/**
2
 * Copyright (C) 2016-2019 Expedia, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.hotels.bdp.waggledance.junit;
17

18
import java.io.ByteArrayOutputStream;
19
import java.io.IOException;
20
import java.io.InputStream;
21
import java.net.InetSocketAddress;
22
import java.nio.channels.Channels;
23
import java.nio.channels.ServerSocketChannel;
24
import java.nio.channels.SocketChannel;
25

26
import org.junit.rules.ExternalResource;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

30
import com.google.common.io.ByteStreams;
31

32
/**
33
 * Emulates a server that only receives packets but doesn't emit responses to any requests.
34
 * <p>
35
 * This class can be used to emulate a Graphite Carbon relay, for example.
36
 * </p>
37
 */
38
public class ServerSocketRule extends ExternalResource {
39
  private static final Logger LOG = LoggerFactory.getLogger(ServerSocketRule.class);
×
40

41
  private final InetSocketAddress address;
42
  private final ByteArrayOutputStream output = new ByteArrayOutputStream();
×
43

44
  private final ServerSocketChannel serverSocketChannel;
45

46
  private int requests = 0;
×
47

48
  public ServerSocketRule() {
×
49
    try {
50
      serverSocketChannel = (ServerSocketChannel) ServerSocketChannel
×
51
          .open()
×
52
          .bind(new InetSocketAddress(0))
×
53
          .configureBlocking(false);
×
54
      address = (InetSocketAddress) serverSocketChannel.getLocalAddress();
×
55
    } catch (IOException e) {
×
56
      throw new RuntimeException(e);
×
57
    }
×
58
  }
×
59

60
  @Override
61
  protected void after() {
62
    LOG.info("Socket closing, handled {} requests", requests);
×
63
    try {
64
      serverSocketChannel.close();
×
65
    } catch (IOException e) {
×
66
      throw new RuntimeException(e);
×
67
    }
×
68
  }
×
69

70
  public byte[] getOutput() {
71
    try {
72
      SocketChannel socketChannel = serverSocketChannel.accept();
×
73
      while (socketChannel != null) {
×
74
        requests++;
×
75
        try (InputStream input = Channels.newInputStream(socketChannel)) {
×
76
          ByteStreams.copy(input, output);
×
77
        }
78
        socketChannel = serverSocketChannel.accept();
×
79
      }
80
    } catch (IOException e) {
×
81
      throw new RuntimeException("Error processing user request", e);
×
82
    }
×
83
    return output.toByteArray();
×
84
  }
85

86
  public int port() {
87
    return address.getPort();
×
88
  }
89

90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc