three reasons why we should not use inheritance in tests 大概意思是: 1. 很多测试里的继承用的不合适。测试也是代码,必须符合继承的原则。 The point of inheritance is to take advantage of polymorphic behavior NOT to reuse code, and people miss that, they see inheritance as a cheap way to add behavior to a class. When I design code I like to think about options. When I inherit, I reduce my options. I am now sub-class of that class and cannot be a sub-class of something else. I have permanently fixed my construction to that of the superclass, and I am at a mercy of the super-class changing APIs. My freedom to change is fixed at co
Read more »

gradle test configurations one sample config ways to improve performance of gradle build common used properties: * jvmArgs: jvm 参数。通常会配置堆栈大小,保证测试对内存的要求。 * '-Xms128m', '-Xmx1024m', '-XX:MaxMetaspaceSize=128m'。-Xms 是初始堆大小,-Xmx 是最大堆大小,-XX:MaxMetaspaceSize 是 class metadata 可占用的最大本地内存(默认是 unlimited)。具体 jvm 参数参考 java doc. * forkEvery: 每个 test process 里跑的 test classes 的最大个数。当次数达到限制后,会自动重启。这定义了一个测试线程什么时候回重启,与并发无关。默认是 0,即无最大限制,就是可以一直跑 * maxParalleForks: 能并发跑的最大 test processes 数目 * systemProperty: 系统属性 * environment:系统环境变量 * include: 具体执行的测试。可以通过这个配置不同的测试级别(单元测试、集成测试、functional 测试……)
Read more »

Synchronous vs multiprocessing vs multithreading vs async Concurrency vs Parralism. asyncio & threading can run multiple I/O operations at the same time. Async runs one block of code at a time while threading just one line of code at a time. With async, we have better control of when the execution is given to other block of code but we have to release the execution ourselves. * IO bound problems: use async if your libraries support it and if not, use threading. * CPU bound problems: use multi-processing. * None above is a problem:you are probably just fine with synchronous code. You may
Read more »

Problems? 1. manifest 是干什么用的? 2. 代码运行时,如何找到 dependency 的包 3. java -jar 时,classpath 指定? classpath classpath 指定的是 java 类所在的目录(包括当前项目的类、依赖的类等)。应该是当打 jar 包的时候,默认会加上当前目录(.)到 classpath,这样就包含了 jar 内部的类? Thin jar gradle lean This plugin depends on JavaPlugin and ApplicationPlugin. * for installDist, jars under install/$PROJECT_NAME$/lib/ * for distZip, jars under /lib/ inside package 1 2 3 4 5 6 7 8 9 10 11 plugins { id 'java' // Apply the application plugin to add support for building a CLI application. id 'application' id 'scala' id 'com.github.maiflai.scalatest' ve
Read more »

背景 1. 项目需要引入 local 第三方包 2. 该第三方包只有 window/linux license,而开发在 macos 3. 开发时,通过 gradle dependency compile files('path/to/thejar.jar') 来引入包 问题 运行时,报错误 java.lang.UnsatisfiedLinkError: no thejar in java.library.path 原因 引入 .dll 或 .so 失败造成。 solution 1. 把 thejar 加入到 path 中 ————— not work 2. 加入 path,并 loadLibrary ——————— not work 3. should work(配置 .dll 或 .so 路径): 1. 配置 PATH 2. 或 jar 包启动时,设置 ‘-Djava.library.path’ 有关 PATH, -classpath, java.library.path 的区别,再 google。java 在使用这三个 path 时: 1. PATH:用来寻找 java, javac 等 command 并执行 2. classpath:jvm 在执行时用来寻找 java class。classpath 一般指向 jar
Read more »

几个核心类 参见: * java api * 入门 - 介绍核心使用组件和最佳实践 SqlSessionFactory mybatis 应用以一个 sqlSessionFactory 实例为核心,即一个应用中有一个单例 SqlSessionFactory,所以数据库 session 都从这里获得。 SqlSessionFactory 可以通过 SqlSessionFactoryBuilder 获得,builder 负责从 xml 配置或 java configuration 类获得。xml (或相应的 java configuration 类) 配置了 datasource(数据库连接信息)、mappers 等信息 SqlSessionFactoryBuilder 它主要就是用来获取 SqlSessionFactory,可以从 xml 或 Java Configuration 类加载配置并构建。提供如下几种方式来获取(参见java api): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // 从 xml 获取,其中配置了 environment,datasource,mappers SqlSessionFactory build(InputStream inputStream); // 从 xml 获取,但当 xml 配置了多个 env
Read more »

traditional authentication 传统认证使用 session: 1. client 发送 username、password 给 server 2. server 查数据库,检查信息,是否正确。正确就把用户登录信息(即用户状态)写到 session 里(即服务器内存中),并将 sessionId 返回给 client。 3. client 在请求 api 时,在 cookie 中传递 sessionId。server 端根据 sessionId 获取用户登录信息,如果已认证,返回正常响应;反之,401 这种方式有个缺陷:如果做分布式服务部署,那么需要每个服务器都要同步相同的登录信息,这不是一个好的方式。所以一般 rest 微服务都要求的是 stateless,即 server 端不保存任何用户信息,请求中包含所有需要的信息。 oauth oauth 是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密的资源(如照片,视频,联系人列表),而无需将用户名和密码提供给第三方应用。 OAuth允许用户提供一个 令牌,而不是用户名和密码来访问他们存放在特定服务提供者的数据。每一个令牌授权一个特定的网站(例如,视频编辑网站)在特定的时段(例如,接下来的2小时内)内访问特定的资源(例如仅仅是某一相册中的视频)。这样,OAuth让用户可以授权
Read more »

asure storage 提供四种存储支持(asure storage overview (youtube)): * blob (binary large object):二进制数据存储。有两种:page blog(只能新增/删除/向已有数据附加数据,不能修改数据);block blog(可以更新) * table:存储表格(nosql) * queue:有库,有 rest api * files:好像主要用在文件共享的时候,就是类似于 windows server 上的文件共享(smb(server message block)),实现和使用方式都和 windows server 的文件共享一样。所以需要支持例如按 /servername/filename 等方式来 share 和 使用文件。它是构建于 blob 之上的。 几个概念 Storage Accout storage 的所有存储都必须在一个 storage account 内发生。这有点类似于一个 database。 安全也是在这里实现: 1. key:创建 account 时,就会生成俩 key,primary key 就是你用来登录访问数据的 key。不过这种方式对于有 client 时不太方便,因为可能不能 share key 2. saas token:就是可以登录认证获得 token,然
Read more »

[MIME 类型](MIME 类型) 是用一种标准化的方式来表示文档的性质和格式。浏览器一般通过 MIME 类型(而不是文档扩展名)来确定如何处理文档。因此服务器传输数据时,必须设置正确的 MIME 类型。 通用结构 1 type/subtype 1. 不允许空格 2. 大小写不敏感,一般都是小写 独立类型 type 可以是独立类型,表示文件的分类,可以是如下值: 类型描述典型示例text表明文件是普通文本,理论上是可读的语言text/plain, text/html, text/css, text/javascriptimage表明是某种图像。不包括视频,但是动态图(比如动态gif)也使用image类型image/gif, image/png, image/jpeg, image/bmp, image/webpaudio表明是某种音频文件audio/midi, audio/mpeg, audio/webm, audio/ogg, audio/wavvideo表明是某种视频文件video/webm, video/oggapplication表明是某种二进制数据application/octet-stream, application/pkcs12, application/vnd.mspowerpoint, application/xhtml+xml, appli
Read more »
0%