use of io.fabric8.kubernetes.client.dsl.internal.PodOperationContext in project kubernetes-client by fabric8io.
the class BaseOperationTest method testSimpleFieldQueryParamConcatenation.
@Test
void testSimpleFieldQueryParamConcatenation() {
Map<String, String> fieldsMap = new HashMap<>();
fieldsMap.put("yesKey1", "yesValue1");
fieldsMap.put("yesKey2", "yesValue2");
PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
operation = (PodOperationsImpl) operation.withFields(fieldsMap).withField("yesKey2", "overrideValue2").withoutField("noKey1", "noValue1").withoutField("noKey2", "noValue2");
final String fieldQueryParam = operation.getFieldQueryParam();
// Use contains to not be depending on map key/value pair ordering
assertThat(fieldQueryParam, containsString("yesKey1=yesValue1"));
assertThat(fieldQueryParam, containsString("yesKey2=overrideValue2"));
assertThat(fieldQueryParam, containsString("noKey1!=noValue1"));
assertThat(fieldQueryParam, containsString("noKey2!=noValue2"));
}
use of io.fabric8.kubernetes.client.dsl.internal.PodOperationContext in project kubernetes-client by fabric8io.
the class BaseOperationTest method testFilterContextModification.
@Test
void testFilterContextModification() {
PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
operation.withField("x", "y");
// should not modify the existing context
assertTrue(Utils.isNullOrEmpty(operation.getFieldQueryParam()));
}
use of io.fabric8.kubernetes.client.dsl.internal.PodOperationContext in project kubernetes-client by fabric8io.
the class PodUpload method uploadDirectory.
private static boolean uploadDirectory(HttpClient client, PodOperationContext context, OperationSupport operationSupport, Path pathToUpload) throws IOException, InterruptedException {
final String command = String.format("mkdir -p %1$s && base64 -d - | tar -C %1$s -xzf -", shellQuote(context.getDir()));
final PodUploadWebSocketListener podUploadWebSocketListener = initWebSocket(buildCommandUrl(command, context, operationSupport), client);
try (final PipedOutputStream pos = new PipedOutputStream();
final PipedInputStream pis = new PipedInputStream(pos);
final Base64.OutputStream b64Out = new Base64.OutputStream(pos, Base64.ENCODE);
final GZIPOutputStream gzip = new GZIPOutputStream(b64Out)) {
podUploadWebSocketListener.waitUntilReady(operationSupport.getConfig().getRequestConfig().getUploadConnectionTimeout());
final Callable<?> readFiles = () -> {
try (final TarArchiveOutputStream tar = new TarArchiveOutputStream(gzip)) {
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
for (File file : pathToUpload.toFile().listFiles()) {
addFileToTar(null, file, tar);
}
tar.flush();
}
return null;
};
final ExecutorService es = Executors.newSingleThreadExecutor();
Future<?> readFilesFuture = es.submit(readFiles);
InputStreamPumper.transferTo(pis, podUploadWebSocketListener::send);
podUploadWebSocketListener.waitUntilComplete(operationSupport.getConfig().getRequestConfig().getUploadRequestTimeout());
try {
readFilesFuture.get(100, TimeUnit.SECONDS);
return true;
} catch (ExecutionException ex) {
if (ex.getCause() instanceof IOException) {
throw (IOException) ex.getCause();
}
throw new IOException(ex.getMessage(), ex.getCause());
} catch (TimeoutException e) {
return false;
} finally {
es.shutdown();
}
}
}
use of io.fabric8.kubernetes.client.dsl.internal.PodOperationContext in project kubernetes-client by fabric8io.
the class BaseOperationTest method testSkippingFieldNotMatchingNullValues.
@Test
void testSkippingFieldNotMatchingNullValues() {
PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
operation = (PodOperationsImpl) operation.withField("key1", "value1").withoutField("key2", "value2").withoutField("key2", null).withoutField("key2", "").withoutField("key2", "value3").withoutField("key10", "value11").withoutField("key10", // Once more to make sure no accidental trailing comma is added
"");
assertThat(operation.getFieldQueryParam(), is(equalTo("key1=value1,key2!=value2,key2!=value3,key10!=value11")));
}
Aggregations