Containers

Can we run applications with a GUI?

Can a docker run a windows application on linux?

Like this Virtual Machine..

Docker containers can run anywhere, on-premises in the customer datacenter, in an external service provider or in the cloud, on Azure. Docker image containers can run natively on Linux and Windows.

However, Windows images can run only on Windows hosts and Linux images can run on Linux hosts and Windows hosts (using a Hyper-V Linux VM, so far), where host means a server or a VM.

Container kernel needs to match host kernel.

Host System

Container

Host System

Container

VM

VM

Now that Docker uses libcontainer rather than LXC as its basis, it is possible that porting of libcontainer in the future could one day allow for running Windows and Mac OS Docker containers on those systems respectively, but it would depend on appropriate OS features being available to allow for containerization.

So why is Docker cool?

much more lightweight than VirtualMachines

Virtual Machines

Docker

So why is Docker cool?

runs on cloud services

So why is Docker cool?

it can scale!

Container Orchestration

Run many containers on a cluster

Scalability

Docker Swarm

Kubernetes

easy

complex

Now back to our Dockerfile...

1. Create                   repository and clone it.

2. Add C++ code.

3. Create                  Dockerfile.

4. Build and tag Docker container.

5. Push container to                        !

6. Modify C++ code.

7. And see what happens...

FROM ubuntu:20.04

MAINTAINER CS410.net version: 0.1


ADD converter.cc converter.cc

RUN apt-get update
RUN apt-get install -y g++
RUN g++ -o converter converter.cc

ENTRYPOINT ["./converter"]

Dockerfile

Functions, Classes

Arrays, Vectors

Templates

Cython

Run our C++ code in Python using Cython

and compare timing against NumPy

Analyze a bunch of numbers and calculate min, max, mean, stddev.

Now: Testing

Testing means checking code for bugs..

STEAMROOT="$(cd "${0%/*}" && echo $PWD)"

# Scary!
rm -rf "$STEAMROOT/"*

This could fail: produce an empty string!

rm -rf /

Testing means checking code for bugs..

Manual Testing

Automatic Testing

Explanatory Testing

Unit Testing

Chapters 7, 8, 9

Integration Testing

System Testing

System Tests

Testing Pyramid

Unit Tests

test individual functions

def inc(x):
    return x + 1
def test_inc():
    assert inc(4) == 5
def test_inc3():
    assert inc('a') == 'b'
def test_inc2():
    assert inc(-1) == 0

throws exceptions

def test_inc4():
    assert inc('a') == 'a1'
# assert(a == b)

if not a==b:
  throw Error()
import sys

def inc(x):
    
    return x+1
    
largestInt = sys.maxsize # maxint

print ( largestInt )

print ( inc( largestInt ) )

Test Driven Development

F.I.R.S.T.

Tests should be FAST

Tests should be INDEPENDENT

Tests should be REPEATABLE

Tests should be SELF-VALIDATING

True or False

Tests should be written in a TIMELY fashion

Pages 132/133

Integration Testing

def test_some_method(parameter):
  '''
  '''

  # return true or false
def test_setup():
  '''
  '''

  # connect to database
  # or span server
def test_teardown():
  '''
  '''

  # delete temporary files
  # or close database connection

1. Setup

2. Test

3. Teardown

pytest

$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-5.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item

test_sample.py F                                                     [100%]

================================= FAILURES =================================
_______________________________ test_answer ________________________________

    def test_answer():
>       assert inc(3) == 5
E       assert 4 == 5
E        +  where 4 = inc(3)

test_sample.py:6: AssertionError
========================= short test summary info ==========================
FAILED test_sample.py::test_answer - assert 4 == 5
============================ 1 failed in 0.12s =============================
# content of test_sample.py
def inc(x):
    return x + 1


def test_answer():
    assert inc(3) == 5

System Testing

Test of the full product

End-to-end Testing

Blackbox Testing

Whitebox Testing

Internals

Externals without knowledge

about what is going on inside

UI Testing

from selenium import webdriver

def test_google():
  
  driver = webdriver.Chrome()
  driver.maximize_window()
  driver.get("https://google.com")

  searchtext = driver.find_element_by_id("searchtext")
  searchtext.send_keys("CS410")
  
  submitbutton = driver.find_element_by_id("submit")
  submitbutton.click()
  
  driver.save_screenshot("/tmp/shot.png")
  

UI Testing

Control a web-browser

const browser = await puppeteer.launch();

const page = await browser.newPage();

await page.setViewport({
    width: 1440,
    height: 900
});
  
await page.goto('https://nsa.gov');

await page.waitFor('input[name=desktopSearch]');
await page.click('input[name=desktopSearch]');

await page.keyboard.type('Area 51');
await page.keyboard.press('Enter');

await page.waitFor(1000);
await page.screenshot({path: 'screenshot.png'});
await browser.close();