16
16
17
17
package com .ibm .watson .modelmesh .payload ;
18
18
19
+ import java .io .IOException ;
19
20
import java .net .URI ;
21
+ import java .security .NoSuchAlgorithmException ;
20
22
21
23
import io .grpc .Metadata ;
22
24
import io .grpc .Status ;
23
25
import io .netty .buffer .ByteBuf ;
24
26
import io .netty .buffer .Unpooled ;
25
27
import org .junit .jupiter .api .Test ;
26
28
29
+ import javax .net .ssl .SSLContext ;
30
+ import javax .net .ssl .SSLParameters ;
31
+
27
32
import static org .junit .jupiter .api .Assertions .assertFalse ;
28
33
29
34
class RemotePayloadProcessorTest {
30
35
36
+ void testDestinationUnreachable () throws IOException {
37
+ URI uri = URI .create ("http://this-does-not-exist:123" );
38
+ try (RemotePayloadProcessor remotePayloadProcessor = new RemotePayloadProcessor (uri )) {
39
+ String id = "123" ;
40
+ String modelId = "456" ;
41
+ String method = "predict" ;
42
+ Status kind = Status .INVALID_ARGUMENT ;
43
+ Metadata metadata = new Metadata ();
44
+ metadata .put (Metadata .Key .of ("foo" , Metadata .ASCII_STRING_MARSHALLER ), "bar" );
45
+ metadata .put (Metadata .Key .of ("binary-bin" , Metadata .BINARY_BYTE_MARSHALLER ), "string" .getBytes ());
46
+ ByteBuf data = Unpooled .buffer (4 );
47
+ Payload payload = new Payload (id , modelId , method , metadata , data , kind );
48
+ assertFalse (remotePayloadProcessor .process (payload ));
49
+ }
50
+ }
51
+
31
52
@ Test
32
- void testDestinationUnreachable () {
33
- RemotePayloadProcessor remotePayloadProcessor = new RemotePayloadProcessor (URI .create ("http://this-does-not-exist:123" ));
34
- String id = "123" ;
35
- String modelId = "456" ;
36
- String method = "predict" ;
37
- Status kind = Status .INVALID_ARGUMENT ;
38
- Metadata metadata = new Metadata ();
39
- metadata .put (Metadata .Key .of ("foo" , Metadata .ASCII_STRING_MARSHALLER ), "bar" );
40
- metadata .put (Metadata .Key .of ("binary-bin" , Metadata .BINARY_BYTE_MARSHALLER ), "string" .getBytes ());
41
- ByteBuf data = Unpooled .buffer (4 );
42
- Payload payload = new Payload (id , modelId , method , metadata , data , kind );
43
- assertFalse (remotePayloadProcessor .process (payload ));
53
+ void testDestinationUnreachableHTTPS () throws IOException , NoSuchAlgorithmException {
54
+ URI uri = URI .create ("https://this-does-not-exist:123" );
55
+ SSLContext sslContext = SSLContext .getDefault ();
56
+ SSLParameters sslParameters = sslContext .getDefaultSSLParameters ();
57
+ try (RemotePayloadProcessor remotePayloadProcessor = new RemotePayloadProcessor (uri , sslContext , sslParameters )) {
58
+ String id = "123" ;
59
+ String modelId = "456" ;
60
+ String method = "predict" ;
61
+ Status kind = Status .INVALID_ARGUMENT ;
62
+ Metadata metadata = new Metadata ();
63
+ metadata .put (Metadata .Key .of ("foo" , Metadata .ASCII_STRING_MARSHALLER ), "bar" );
64
+ metadata .put (Metadata .Key .of ("binary-bin" , Metadata .BINARY_BYTE_MARSHALLER ), "string" .getBytes ());
65
+ ByteBuf data = Unpooled .buffer (4 );
66
+ Payload payload = new Payload (id , modelId , method , metadata , data , kind );
67
+ assertFalse (remotePayloadProcessor .process (payload ));
68
+ }
44
69
}
45
70
}
0 commit comments