How to use downloadedLayerSize method of org.testcontainers.images.LoggedPullImageResultCallback class

Best Testcontainers-java code snippet using org.testcontainers.images.LoggedPullImageResultCallback.downloadedLayerSize

Source:LoggedPullImageResultCallback.java Github

copy

Full Screen

...54 }55 }56 if (statusLowercase.startsWith("pulling from" ) || statusLowercase.contains("complete" )) {57 long totalSize = totalLayerSize();58 long currentSize = downloadedLayerSize();59 int pendingCount = allLayers.size() - downloadedLayers.size();60 String friendlyTotalSize;61 if (pendingCount > 0) {62 friendlyTotalSize = "? MB";63 } else {64 friendlyTotalSize = byteCountToDisplaySize(totalSize);65 }66 logger.info("Pulling image layers: {} pending, {} downloaded, {} extracted, ({}/{})",67 format("%2d", pendingCount),68 format("%2d", downloadedLayers.size()),69 format("%2d", pulledLayers.size()),70 byteCountToDisplaySize(currentSize),71 friendlyTotalSize);72 }73 if (statusLowercase.contains("complete")) {74 completed = true;75 }76 }77 @Override78 public void onComplete() {79 super.onComplete();80 final long downloadedLayerSize = downloadedLayerSize();81 final long duration = Duration.between(start, Instant.now()).getSeconds();82 if (completed) {83 logger.info("Pull complete. {} layers, pulled in {}s (downloaded {} at {}/s)",84 allLayers.size(),85 duration,86 byteCountToDisplaySize(downloadedLayerSize),87 byteCountToDisplaySize(downloadedLayerSize / duration));88 }89 }90 private long downloadedLayerSize() {91 return currentSizes.values().stream().filter(Objects::nonNull).mapToLong(it -> it).sum();92 }93 private long totalLayerSize() {94 return totalSizes.values().stream().filter(Objects::nonNull).mapToLong(it -> it).sum();95 }96}...

Full Screen

Full Screen

downloadedLayerSize

Using AI Code Generation

copy

Full Screen

1public class DockerImageSize {2 public static void main(String[] args) throws Exception {3 DockerClient dockerClient = DockerClientBuilder.getInstance().build();4 LoggedPullImageResultCallback callback = new LoggedPullImageResultCallback();5 dockerClient.pullImageCmd("busybox").exec(callback);6 long size = callback.awaitCompletion().downloadedLayerSize();7 System.out.println("Size of the docker image downloaded: " + size);8 }9}

Full Screen

Full Screen

downloadedLayerSize

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.GenericContainer2import org.testcontainers.containers.output.Slf4jLogConsumer3import org.testcontainers.containers.output.OutputFrame4import org.testcontainers.images.LoggedPullImageResultCallback5import org.slf4j.LoggerFactory6import java.util.concurrent.TimeUnit7class DownloadedImageSize extends LoggedPullImageResultCallback {8 private static final Logger logger = LoggerFactory.getLogger(DownloadedImageSize.class)9 void onNext(PullResponseItem item) {10 if (item.getDownloadedLayerSize() > 0) {11 logger.info("Downloaded image size: ${item.getDownloadedLayerSize()}")12 }13 super.onNext(item)14 }15}16def logConsumer = new Slf4jLogConsumer(LoggerFactory.getLogger("mylogger"))17def callback = new DownloadedImageSize()18def container = new GenericContainer<>("alpine:3.9")19container.withLogConsumer(logConsumer)20container.withStartupAttempts(1)21container.withStartupTimeout(60000, TimeUnit.MILLISECONDS)22container.withCommand("sleep", "10")

Full Screen

Full Screen

downloadedLayerSize

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.images.LoggedPullImageResultCallback2import org.testcontainers.DockerClientFactory3import org.testcontainers.utility.DockerImageName4def imageName = DockerImageName.parse("openjdk:8u212-jdk-alpine3.9")5def dockerClient = DockerClientFactory.instance().client()6def callback = new LoggedPullImageResultCallback()7dockerClient.pullImageCmd(imageName).exec(callback)8println(imageLayerSize)9import org.testcontainers.images.LoggedPullImageResultCallback10import org.testcontainers.DockerClientFactory11import org.testcontainers.utility.DockerImageName12def imageName = DockerImageName.parse("openjdk:8u212-jdk-alpine3.9")13def dockerClient = DockerClientFactory.instance().client()14def callback = new LoggedPullImageResultCallback()15dockerClient.pullImageCmd(imageName).exec(callback)16println(imageLayerSize)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcontainers-java automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in LoggedPullImageResultCallback

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful